var content;
fs.readFile(\'./Index.html\', function read(err, data) {
if (err) {
throw err;
}
content = data;
});
console.log(content);
>
Use the built in promisify library (Node 8+) to make these old callback functions more elegant.
const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);
async function doStuff() {
try {
const content = await readFile(filePath, 'utf8');
console.log(content);
} catch (e) {
console.error(e);
}
}