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

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

server - How to make a node.js application run permanently?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...