4 ms·
> It was using fs.readFile without waiting for a callback. This is why I always use fs.readFileSync or correctly implement the callback and read it sequentiall
by softfalcon 4y ago
> It was using fs.readFile without waiting for a callback.
This is why I always use fs.readFileSync or correctly implement the callback and read it sequentially myself as it feeds me chunks of the file data buffer via the callback.
You can also use TypeScript and await on the promise which is super clean, highly recommend it.
All in all, node's file system libs are pretty solid.
- rantallion 4y ago> You can also use TypeScript and await on the promise I'm not sure what you mean here. The promises and async/await syntax come from JavaScript, not from TypeScript - TS is just the sugar on top that provides the typings.
- softfalcon 4y agoYup, you’re right… I just had a brain fart lol.
- nicoburns 4y agoRecent versions of node have an ‘fa/promises’ module and event support top-level await natively. So you can just await fs.readFile where fs here is the promises version of the module.