xuan hung Nguyen
xuan hung Nguyen

Reputation: 398

How to run Node.js 24/7 in Server CentOS 6.5?

I know I can run Node.js on server with command line node app.js.

But when I am out of control server, the session will be close and end my command. I don't know how to make a service run Node.js 24/7 like another in Server.

I follow this post, but I'm not using express.

Upvotes: 3

Views: 3074

Answers (2)

karthick
karthick

Reputation: 6168

You can make it happen by many ways.

  1. You can append & in the command line to make the node server run in background.

    node app.js > stdout.txt > stderr.txt &
    
  2. Via process manager pm2, It gives more features, you can monitor all the processes pm2 monit, auto restart, etc

    npm install pm2 -g
    
    pm2 start app.js
    
  3. or, using following npm packages

Nodemon - nodemon app.js

Forever - forever start app.js.

Upvotes: 2

Nilasis Sen
Nilasis Sen

Reputation: 309

run it using forever , it helps the server to restart whenever the node server get crashed. https://www.npmjs.com/package/forever

Upvotes: 3

Related Questions