“fs.writefile” Kode Jawaban

fs.writefile

const fs = require('fs');

fs.writeFile("/tmp/test", "Hey there!", function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("The file was saved!");
}); 

// Or
fs.writeFileSync('/tmp/test-sync', 'Hey there!');
Jeff Spicoli

NodeJS ReadFile

const fs = require('fs');

fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
  if (err) {
    console.error(err);
    return
  }
  console.log(data);
});
Light Locust

data tidak menulis di node file js

const fs = require('fs');

fs.readFile('file.txt', 'utf-8', (err, data) => {
    if(err) {
        throw err;
    }
    console.log(data);
});
Disgusted Dragonfly

fs.readfile

fs.readFile('filename', function read(err, data) {
    if (err) {
        throw err;
    }
    var content = data;
  
    console.log(content);  
   
});
If-dev

WriteFile di Node 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

WriteFile di Node JS

fs.writeFile('2pac.txt', 'Some other lyric', 'ascii', callback);
Testy Tamarin

Jawaban yang mirip dengan “fs.writefile”

Pertanyaan yang mirip dengan “fs.writefile”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya