Now that we have mostly tackled various techniques of improving our frontend assets, it's time to concentrate on the server-side stuff. In the rest of the chapter, we will explore techniques that can make our application faster and more responsive.
You are probably familiar with the synchronous functions provided by the fs
native Node module by now. The most common example is the one for reading a file:
var content = fs.readFileSync(filePath);
We should really avoid having this anywhere apart from having it beside the boot time (when the application spins up), because it will block the event loop (and make every client wait for this to finish). Doing this only once isn't a big deal, but when you're reading a file synchronously for each request made to the server, for example, it's going to block the event loop over and over again.
There are asynchronous counterparts to these functions, and we should use them as much as we can. However, if you...