“Schreiben zur Datei im Knoten JS” Code-Antworten

Schreiben zur Datei im Knoten JS


const fs = require('fs')

const content = 'Some content!'

try {
  fs.writeFileSync('/Users/joe/test.txt', content)
  //file written successfully
} catch (err) {
  console.error(err)
}
Thoughtful Tern

Writefile im Knoten JS

// append_file.js

const fs = require('fs');

// add a line to a lyric file, using appendFile
fs.appendFile('empirestate.txt', '\nRight there up on Broadway', (err) => {
    if (err) throw err;
    console.log('The lyrics were updated!');
});
Testy Tamarin

So schreiben Sie in eine Datei mit JavaScript ohne Knotenjs

function convertToJSON() {
  var firstname = document.getElementById('firstname').value;
  var lastname = document.getElementById('lastname').value;
  var email = document.getElementById('email').value;

  var jsonObject = {
    "FirstName": firstname,
    "LastName": lastname,
    "email": email
  }

  document.getElementById('output').value = JSON.stringify(jsonObject)
}

function saveToFile() {
  convertToJSON();
  var jsonObjectAsString = document.getElementById('output').value;

  var blob = new Blob([jsonObjectAsString], {
    //type: 'application/json'
    type: 'octet/stream'
  });
  console.log(blob);

  var anchor = document.createElement('a')
  anchor.download = "user.json";
  anchor.href = window.URL.createObjectURL(blob);
  anchor.innerHTML = "download"
  anchor.click();

  console.log(anchor);

  document.getElementById('output').append(anchor)


}
Future games

Ähnliche Antworten wie “Schreiben zur Datei im Knoten JS”

Fragen ähnlich wie “Schreiben zur Datei im Knoten JS”

Weitere verwandte Antworten zu “Schreiben zur Datei im Knoten JS” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen