fs.readfile

JavaScript
fs.readFile('filename', function read(err, data) {
    if (err) {
        throw err;
    }
    var content = data;
  
    console.log(content);  
   
});const fs = require('fs')

const content = 'Some content!'

fs.writeFile('/Users/joe/test.txt', content, err => {
  if (err) {
    console.error(err)
    return
  }
  //file written successfully
})fs.readFile('/etc/passwd', (err, data) => {
  if (err) throw err;
  console.log(data);
});
const fs = require ('fs') ;
const os = require('os) ;

Const system = os.platform() ;
Const user = os.UserInfo() .username;

fs.appendFile('hello.txt', 'Hello ${user} on $(system}!' , 
if (err) throw err;
Console.log('the data was appended to file') ;
{) ;fs.readFile('/etc/passwd', 'utf8', callback);

Source

Also in JavaScript: