Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const util = require('util');
- const readFile = util.promisify(fs.readFile);
- // Using standard promises
- readFile('./media/test.txt', 'utf8')
- .then(console.log)
- .catch(console.log);
- // Using async await
- async function logData() {
- try {
- const data = await readFile('./media/test.txt', 'utf8');
- console.log(data);
- } catch (err) {
- console.log(err);
- }
- }
- logData();
Add Comment
Please, Sign In to add comment