Tips to run nodejs server permanently

I have figured it out and feel like sharing it here for others to use and save time.

There are 3 ways to run your nodejs app permanently on ubuntu linux machines.

Use ampersand (&) at the end of your command. enter this command “nodejs feed.js &” (without the double quote).
Use forever command of npm package
User pm2 command of npm package

More details

On using the ampersand at the end of your command “nodejs feed.js &” it should be entered at the current directory.
Before using the forever or pm2 module, you have to install the npm package by entering this command “sudo apt-get install npm”

After npm package installation and plan to use forever module, you have to install the forever module by entering this command “sudo npm install forever -g”
after forever installation, you’re now ready to run your nodejs app permanently by typing this command “sudo forever start server.js”

Now using the pm2 module which i highly recommended to use. enter this command to install pm2 module “sudo npm install pm2 -g”. after pm2 module installation, you’re now ready to run your nodejs permanently by typing this command “pm2 start feed.js”
other pm2 command that may useful.

to stop the pm2, just type this command “pm2 stop feed”

The last option to run nodejs apps permanently is the most stable option that I have tested so far. Also, you can use keymetrics.io for Free online monitoring dashboard.

option 1 is not stable
option 2 using forever is good but not great
pm2 module rocks and save a lot of time.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: