PJ_ PJ_ - 1 year ago 94
Node.js Question

Permanent socket.io server on Ubuntu Linux

I'm starting a socket.io server by entering a command:

node server.js

But that sometimes stops, or I need to have a terminal window open for it to run.

How can I set this up on a Linux server (Ubuntu) so there is a permanent server running in the system (like Apache) and if it stops it restarts automatically?

Answer Source

You can use PM2

after install the npm package you can use pm2 command line :

pm2 start server.js

You can use too nodemon or forever to detect when your server files changed. It will restart automatically your server and you don't need anymore to stop / start your node application.

Note than pm2 is used for production and nodemon for development

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download