Why Isn't My Readfilesync Function Executing?
I'm trying to read from a file in Node. Here is my code: const cheerio = require('cheerio'); var fs = require('fs'); var path = process.argv[2]; var glossArr = [] fs.readFileSy
Solution 1:
readFileSync
doesn't accept a callback parameter because it's synchronous. You need to change your code to move the code from within the callback to beneath the synchronous function:
var markup = fs.readFileSync(path, {encoding: "utf8"});
const $ = cheerio.load(markup);
// ...
To clarify, the readFileSync
is being executed, it's just that you aren't doing anything with the result and your callback parameter is being ignored.
Solution 2:
fs.readFileSync Synchronous version of fs.readFile(). Returns the contents of the path Once the content is returned you can perform the task you want to do. for more understanding use the following link readFileSync
Post a Comment for "Why Isn't My Readfilesync Function Executing?"