Skip to content

Instantly share code, notes, and snippets.

@atomize
Created April 28, 2020 19:49
Show Gist options
  • Save atomize/bea5a3709490081304a758c71cf40952 to your computer and use it in GitHub Desktop.
Save atomize/bea5a3709490081304a758c71cf40952 to your computer and use it in GitHub Desktop.
Asynchronous version of Node.js readFile.
// make Promise version of fs.readFile() - enc is the encoding (i.e. utf-8)
fs.readFileAsync = function (filename, enc) {
return new Promise(function (resolve, reject) {
fs.readFile(filename, enc, function (err, data) {
if (err) reject(err);
else resolve(data);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment