Created
February 13, 2022 20:07
-
-
Save iMichaelOwolabi/05bedf5465d43e966bc646be3bb78d84 to your computer and use it in GitHub Desktop.
How to read file in Node.js in a way that it doesn't block the event loop code sample
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
// A better way of reading file that doesn't block the event loop | |
const fs = require('fs'); | |
fs.readFile('countries.csv', (error, data) => { | |
if (error) { | |
throw new Error(error); | |
} | |
console.log(data.toString()); | |
}); | |
// Other JavaScript code below this line will not be blocked which is good. | |
console.log('OTHER JAVASCRIPT THAT IS NOT BLOCKED'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment