Keeping NodeJS Applications Running Forever Using PM2 Image Keeping NodeJS Applications Running Forever Using PM2

If you write an application that you need to keep running forever on your servers then this is the tutorial for you.

If you're a software developer working on business critical applications and have to adhere to strict Service Level Agreements (SLAs for short) then you know just how vital it is to have your applications back up and running the second they fall over, every second counts when trying to achieve the 5 9's or 99.999% availability throughout the year. In this tutorial I'll be demonstrating the effectiveness of PM2 which is a production process manager for Node.js applications which also features a built-in load balancer for those high-performance applications.

PM2 is an opensource bit of tech that's currently available here: https://github.com/Unitech/pm2 and is currently owned and maintained by an Alexandre Strzelewicz from http://keymetrics.io for those of you who want to check out his other work.

Installing PM2

PM2 doesn't require much configuration, if any, and if you've got NPM installed on your machine then installing PM2 is just a case of running the following command:

1
npm install pm2 -g

Once that's installed on your machine then you are then ready to go.

Starting an Application

Starting a node application that you want to keep running forever is as simple as this:

1
pm2 start app.js

More Info

PM2's official can be found here: http://pm2.keymetrics.io/ should you wish to read up a bit more on this pretty amazing opensource tool and potentially thank the developers for their efforts.

Was This Post Helpful?
Submit a PR: Edit on Github