To load file with Node, we call the readFile
method.
For instance, we write
const fs = require("fs");
fs.readFile(__dirname + "/test.txt", (err, data) => {
if (err) {
throw err;
}
console.log(data.toString());
});
to call readFile
with path of the file to read from.
And we get the file data from data
in the callback.