Any Node.js instance runs in a single thread. If any error occurs, the thread breaks, the server stops, and you need to restart the server. To take advantage of all the cores available in a system, Node.js provides an option to launch a cluster of Node.js processes so that the load is evenly distributed. There are many tools available that do the same thing. We will look at a basic example and then learn about automated tools such as PM2. Let's get started:
- The first step is to create an express server. We will need express, debug, body-parser, and cookie-parser. Open up a Terminal and hit the following:
npm install body-parser cookie-parser debug express typescript --save
- Next, we download the types ...