Last active
April 9, 2023 08:49
-
-
Save syafiqfaiz/2b1a8d0e0467315591839288717c2e85 to your computer and use it in GitHub Desktop.
Node blocking and non blocking IO
This file contains 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
const fs = require('fs'); | |
console.log('hi 1') | |
const data = fs.readFileSync('./file.md', 'utf8'); // blocks here until file is read | |
console.log(data); | |
console.log('hi 3') |
This file contains 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
2 |
This file contains 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
// Non-blocking | |
console.log('hi 1') | |
const fs = require('fs'); | |
fs.readFile('./file.md','utf8', (err, data) => { | |
if (err) throw err; | |
console.log(data); | |
}); | |
console.log('hi 3') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment