The essential tool for deploying a NodeJS application to production
NicolasBrondinBernard
To deploy Node, a simple `node app.js` is not enough to be safe!

Article published on 08/09/2020, last updated on 10/08/2026
If you have already tried deploying a NodeJS application on one of your servers internally, on a VPS, or even on a cloud PaaS-type infrastructure, you already know the challenges of such a deployment.
If you're one of the other people and your first deployment is coming up, you should expect three things:
- Having to find a way to keep your Node application alive even if it happens to crash
- Wanting to retrieve the application logs even after it has closed
- The Node process needing to be independent of your current SSH session, otherwise it will shut down as soon as you end the connection
When you launch a process from an SSH connection, the parent becomes the SSH process, and if it stops, its children stop too!
But don't panic! All these issues (and many others) can be solved with a single tool: PM2
What is it?
PM2 is a powerful process manager specialized for putting NodeJS applications into production!
This means that it's no longer you who will launch your nodejs process directly with your own hands, but you will delegate this task to PM2 so that it can manage the launch of one (or several) processes, store the logs, monitor the resources used, etc... And of course, restart your application when needed!
Be careful, this means that your application must not store its state in RAM, this is what we call a Stateless application
PM2 is a daemon, which means it's a process that runs in the background and will keep running until it is told to stop.
I've presented you with the most basic features and those you'll find immediately useful, but know that it's a more powerful tool than that, it can notably:
- Deploy several processes simultaneously, like micro-services for example
- Automatically reload the app when the code changes
- Restart the process with zero downtime
- Deploy in cluster mode
- ...
Deployment
PM2 is available as a Node package, so you can install it directly from NPM (or Yarn) like this:
npm install pm2@latest -g
Once installed, all you need to do is launch your application!
pm2 start app.js
Then all you need to do is control your Node processes, by displaying real-time logs for example:
pm2 logs
Or by examining resource monitoring!
pm2 monit
And that's it. For more advanced features, I'll let you check out the tool's documentation available here: https://pm2.keymetrics.io/docs/usage/quick-start/
Complete courses, exercises and certificates to really learn programming!
4.8 average rating
PM2 - Home
No comments yet