1// load fs
2const fs = require("fs");
3// read the file
4const content = fs.readFileSync("./my_file.txt");
5// print it
6console.log(content.toString());
1// macOS, Linux, and Windows
2fs.readFileSync('<directory>');
3// => [Error: EISDIR: illegal operation on a directory, read <directory>]
4
5// FreeBSD
6fs.readFileSync('<directory>'); // => <data>
1fs.readFile('filename', function read(err, data) {
2 if (err) {
3 throw err;
4 }
5 var content = data;
6
7 console.log(content);
8
9});