Node.js Process Manager

Updated on Oct 5, 2023

PM2 and NPM share letters in their abbreviations. However, they are entirely different managers. While NPM stands for Node Package Manager, PM stands for Process Manager. With PM2, which is the version we will discuss in this tutorial, you can easily manage and monitor your Node.js processes. It does not come with the default Node.js package but is extremely easy to install. Simply use this command: npm install pm2 -g

The command will install PM2 on your system and connect it to your Node.js installation so you can use it immediately. Once it is set up, you can start, stop, or restart any Node.js application. Like NPM, PM2 uses CLI instead of a graphical interface, but the commands are so intuitive you will memorize them instantly. Here are a few of the most important ones:

  • pm2 list - Lists all Node.js processes and their status;
  • pm2 start - Start a Node.js application, which will be kept alive until stopped, even through system restarts. Add the startup file of the application after the command;
  • pm2 stop - Stop a Node.js process. You can use the process’ ID or name;
  • pm2 restart - Restart a Node.js process. You can use the process’ ID or name;
  • pm2 delete - Delete a Node.js process from the PM2 process list. That does not delete the application itself. You can use the process’ ID or name.

Here is a quick example how to use PM2, and what it looks like. To start your application with you will need to input the following command via the console.

pm2 start app.js

Starting a nodejs app with pm2

You will be presented with a table containing all the applications you have added to PM2. In our case, since this is our first app, the table only has one entry. Please note that using the command will give an automatic name to the application which you will have to then use as a reference when executing PM2 commands against the application. For example, to stop the PM2 monitoring over the app.js application get the name of the application using this command.

pm2 ls

That will bring the table with all the applications again. Find the server application which should be currently online. To stop it just run this command.

pm2 stop app

Stopping a nodejs application via pm2

The application will then be listed as stopped.

PM2 is extremely useful if you want to keep your application up and running indefinitely, even if there is a system restart. Typically, if a system is restarted, all running processes are stopped. Then, the ones that are supposed to begin anew when the system comes back online go online themselves. Node.js does not have that functionality by default, which is why PM2 is so useful. It can also show you vital information about your application, how it is running, and if there are any issues with it.

On this page...

    Node.js Hosting

    • Multiple Node Versions
    • 24/7 Node.js Support
    • Free Domain Transfer
    • Hack-free Protection
    • Fast SSD Storage
    • Free Node.js Transfer
    • Free Cloudflare CDN
    • Immediate Activation
    View More