4 ms·
node.js does not impose it for everything. Every command in the fs library that has a natural synchronous interpretation (like reading a file, writing a file,
by sheetjs 13y ago
node.js does not impose it for everything. Every command in the fs library that has a natural synchronous interpretation (like reading a file, writing a file, ...) has a sync equivalent (readFileSync, writeFileSync, ...)
- ef4 13y agoTrue, and that helps for cases where you're willing to completely sacrifice concurrency. But there's no reason we couldn't have syntactically synchronous code that still runs concurrently.
- camus2 13y agoTry to do that on a production server that has to handle 1000 requests readFileSyncing at the same time ... sync apis are just a conveniance for console applications, they are not meant for a web server. So yes node.js DOES impose async programming for everything or node doesnt scale.
- babby 13y agoSync is great for initialization. Due to the fact you only start up once, you can be as reckless with your performance hindering practices as much as you want as it will never amount to anything more than a few hundred extra milliseconds of startup time.
- akbar501 13y ago> Sync is great for initialization. This is an interesting point. I've found in practice that the speed of server startup times depends on the scale of operations. For example, at a small scale, a 600 ms vs. a 1.2 sec startup makes little difference. However, at scale such differences can matter. More so when something is going wrong that's causing erratic restarts.