Guest User

Untitled

a guest
Jun 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. const fs = require('fs');
  2. const util = require('util');
  3.  
  4. const readFile = util.promisify(fs.readFile);
  5.  
  6. // Using standard promises
  7. readFile('./media/test.txt', 'utf8')
  8. .then(console.log)
  9. .catch(console.log);
  10.  
  11. // Using async await
  12. async function logData() {
  13. try {
  14. const data = await readFile('./media/test.txt', 'utf8');
  15. console.log(data);
  16. } catch (err) {
  17. console.log(err);
  18. }
  19. }
  20.  
  21. logData();
Add Comment
Please, Sign In to add comment