Skip to content

Instantly share code, notes, and snippets.

@syafiqfaiz
Last active April 9, 2023 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syafiqfaiz/2b1a8d0e0467315591839288717c2e85 to your computer and use it in GitHub Desktop.
Save syafiqfaiz/2b1a8d0e0467315591839288717c2e85 to your computer and use it in GitHub Desktop.
Node blocking and non blocking IO
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')
// 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