Created
April 28, 2020 19:49
-
-
Save atomize/bea5a3709490081304a758c71cf40952 to your computer and use it in GitHub Desktop.
Asynchronous version of Node.js readFile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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