“NodeJS Readfile” Kod odpowiedzi

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

ReadfileSync

const fs = require('fs')

try {
  const data = fs.readFileSync('/Users/joe/test.txt', 'utf8')
  console.log(data)
} catch (err) {
  console.error(err)
}
Light Locust

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

odczyt plik nodejs

const fs = require('fs')

try {
  const data = fs.readFileSync('/Users/joe/test.txt', 'utf8')
  console.log(data)
} catch (err) {
  console.error(err)
}
Ofir Salem

Synchronizacja plików odczytu węzła

// macOS, Linux, and Windows
fs.readFileSync('<directory>');
// => [Error: EISDIR: illegal operation on a directory, read <directory>]

//  FreeBSD
fs.readFileSync('<directory>'); // => <data>
Grotesque Gharial

Fs.Readfile

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

Odpowiedzi podobne do “NodeJS Readfile”

Pytania podobne do “NodeJS Readfile”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu