Limit the number of NodeJS processes

You have installed a NodeJS server on your development machine or on a server, test or production. You have especially noticed that the node.exe processes are numerous and each consume several hundred MB of RAM. The reason is simple: in its default configuration, Node JS creates 1 process per processor core. This means that if your PC or server is equipped with an 8-core CPU, there will be 8 node.exe processes that can each consume 300, 350, 400, 450MB of physical RAM, or maybe 5GB of RAM for the NodeJS server. On a Windows or Windows Server machine, it is the node.exe process with description “Node.js: Server-side JavaScript” that is affected.

Example with a virtual machine equipped with 2 cores (VM with 2 vCPUs):

Windows process node.exe node.js nodejs

This tutorial explains how limit the number of Node.js server processes to save the RAM (random access memory) of a Windows server. Interesting for a test or acceptance server, or even for a web developer or an R&D platform, this limitation will not be recommended in a production environment where the maximum performance of the server hardware will be sought.

Node.js is a software platform for applications that need to be scalable, such as a web or SaaS application. NodeJS integrates a web server which allows the execution of JavaScript on the server side. The largest use a Node.js web server: PayPal, SAP, Linkedin, Groupin, Microsoft, Rakuten, Sage …

And on the contrary, we can increase the amount of RAM used by the Nodejs server.

Node.js: limit RAM memory consumption

By default, there is 1 NodeJS process per core so 300MB of RAM x number of CPU cores.

1. On the computer that hosts Node.js, open a Command Prompt (cmd) as Administrator.

Windows 10 prompts cmd commands as administrator

2. Go to the Node.js installation folder, for example:

cd C:nodejsbin

3. Edit the NSSM service:

nssm edit NomService

4. On the tab Application, in the field Settings, add “ -f 1 At the end of the line to define a single process at most NodeJS (space, dash f space 1):

nodejs nssm edit

5. Click on ” Edit the service To save the changes.

6. To restart the Nodejs server to apply the change in the number of processes.

Leave a Comment