Run nodejs application in background

There are several ways to do this, you can either use nohup, or append & at the end of command – personally, I’ve found forever to do the job perfectly fine.
Assuming you already have npm installed, if not, just do

sudo apt-get install npm

Then install forever

npm install forever --global

Now you can run it like this

forever start app.js

And it will take care of everything.

/usr/bin/env: node: No such file or directory

Can be fixed by creating symlink.

cd /usr/bin
sudo ln -s nodejs node

View list of running nodejs apps in forever

root@ubuntu:/# forever list
info:    Forever processes running
data:        uid  command         script forever pid   id logfile                 uptime       
data:    [0] mqgC /usr/bin/nodejs app.js 29570   31398    /root/.forever/mqgC.log 0:1:25:6.344 

To see logs for your application, do forever logs + ID of the app ( in our list it’s [0] – 0 )

root@ubuntu:/# forever logs 0
data:    app.js:31398 - Node app is running on port 5000

Write a Comment