4 ms·
Is there an advantage to using "await fs.readFile" over "fs.readFileSync"?
by ihuman 7y ago
Is there an advantage to using "await fs.readFile" over "fs.readFileSync"?
- mayank 7y agoYou haven't blocked the entire event loop (i.e., other async functions that may be waiting on I/O) while the file is being read.
- hombre_fatal 7y agoSynchronous code blocks the event loop, so in real world code you'd only use the sync-version in some special cases, like when you're reading config files before you "server.boot()" and other scenarios where it's just a one-time cost. Though the few sync functions in the stdlib become less and less convenient, first when promises came out, then with async/await, and now with top-level await.