G_Man
G_Man

Reputation: 1343

Node.js how to keep it running on CentOS?

Recently I have setup Node, Express and Jade on a CentOS 6.5 box with no other web servers or anything. I have the site working but in order to keep it up and running I have to leave a putty window open with the server running. So far no issue but if I lose power or internet my SSH connection is lost and the site goes down. Is there a way to keep my app.js running regardless of my SSH state?

Upvotes: 1

Views: 6947

Answers (2)

dcparham
dcparham

Reputation: 291

i know this is old; but, my CentOS will not "sudo yum install forever" - gives error: "No package forever available". so i tried

"sudo -u [appuser] nohup node [path_to_your_app] > [path_to_log_file] 2>&1 &", where;

[appuser] = admin
[path_to_your_app] = server.js
[path_to_log_file] = log.txt.

still, in 5 min the sever timed out due to "broken pipe" and web page running via node server, stopped.

Upvotes: 0

Vadim Baryshev
Vadim Baryshev

Reputation: 26199

You need to daemonize your application. There are many different ways to do it.

  1. You can use daemon module for node.js.
  2. You can start your application inside of 'screen'.
  3. You can start your application with nohup util:

    sudo -u [appuser] nohup node [path_to_your_app] > [path_to_log_file] 2>&1 &
    

Upvotes: 4

Related Questions