node.js takes care of this for you. All networking I/O in node without exception is done asynchronously and does not block the event loop. There is simply no synchronous networking API provided by node core. There is no need, and you should not, add additional calls to setImmediate
, nextTick
, or setTimeout
as these will complicate your code and not provide any performance benefit.
The only time you need to hand-code yielding the event loop is in lengthy CPU processing such as cryptography, but all your standard DB-backed web site HTTP CRUD/REST operations and streaming data are perfectly fine to code without any explicit forcing of event loop ticks.
And as to synchronous IO for filesystem or child_processes, once you are running a network server, you should use the asynchronous calls exclusively. The synchronous calls are for initial application loading/startup and non-server command line, single-end-user scripts.
To clarify your example: this is NOT I/O:
response.writeHead(200, "OK", {'Content-Type':'text/plain'});
That is writing an in-memory string to an in-memory buffer which will be sent to libuv to be sent across the network by the OS. This is fast and does not require treatment as a slow asynchronous IO operation.