Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run node.js app forever when console is closed?

Tags:

node.js

I connect to my remote server via ssh. Then I start my node.js app with Forever. Everything works fine until I close my console window. How to run node.js app FOREVER on my remote server even when I close my connection via ssh? I just want to start an app and shut down my copmputer. My app should be working in the background on my remote server.

like image 594
Pono Avatar asked Apr 28 '11 11:04

Pono


People also ask

How do I run a node js app permanently?

js application locally after closing the terminal or Application, to run the nodeJS application permanently. We use NPM modules such as forever or PM2 to ensure that a given script runs continuously. NPM is a Default Package manager for Node.

How long will node js last?

Major Node. js versions enter Current release status for six months, which gives library authors time to add support for them. After six months, odd-numbered releases (9, 11, etc.) become unsupported, and even-numbered releases (10, 12, etc.)


1 Answers

You may also want to consider using the upstart utility. It will allow you to start, stop and restart you node application like a service. Upstart can configured to automatically restart your application if it crashes.

Install upstart:

sudo apt-get install upstart 

Create a simple script for your application that will look something like:

#!upstart description "my app"  start on started mountall stop on shutdown  # Automatically Respawn: respawn respawn limit 99 5  env NODE_ENV=production  exec node /somepath/myapp/app.js >> /var/log/myapp.log 2>&1 

Then copy the script file (myapp.conf) to /etc/init and make sure its marked as executable. Your application can then be managed using the following commands:

sudo start myapp sudo stop myapp sudo restart myapp 
like image 169
Derrish Repchick Avatar answered Sep 18 '22 18:09

Derrish Repchick