9951 explained code solutions for 126 technologies


nodejsHow to read file


const fs = require('fs');

fs.readFile("/tmp/test.txt", "utf8", (err, data) => {
  console.log(data);
});ctrl + c
fs.readFile(

reads file and returns data in callback function

/tmp/test.txt

path to text file to read

utf8

encoding to read text in

console.log(data)

log date from file to console