Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

On a Debian server, I installed Node.js. I understand how to launch an app from putty with this command line:

node /srv/www/MyUserAccount/server/server.js

and get to it on the address 50.51.52.53:8080 (IP and port).

But as soon as I close putty, then I cannot reach the address 50.51.52.53:8080 anymore.

How to make a Node.js application run permanently?

As you can guess, I am a beginner with Linux and Node.js.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

You could install forever using npm like this:

sudo npm install -g forever

And then start your application with:

forever server.js

Or as a service:

forever start server.js

Forever restarts your app when it crashes or stops for some reason. To restrict restarts to 5 you could use:

forever -m5 server.js

To list all running processes:

forever list

Note the integer in the brackets and use it as following to stop a process:

forever stop 0

Restarting a running process goes:

forever restart 0

If you're working on your application file, you can use the -w parameter to restart automatically whenever your server.js file changes:

forever -w server.js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...