Created
April 9, 2019 23:28
-
-
Save PabloRegen/4b26424c3b1996ac46828823b3ac027b to your computer and use it in GitHub Desktop.
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
// Blocking | |
const fs = require('fs'); | |
const data = fs.readFileSync('/file.md'); // blocks here until file is read | |
console.log(data); | |
moreWork(); // will run after console.log | |
// Non-blocking | |
const fs = require('fs'); | |
fs.readFile('/file.md', (err, data) => { | |
if (err) throw err; | |
console.log(data); | |
}); | |
moreWork(); // will run before console.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment