2

I have installed the nodejs server on Ubuntu 14.04.2 LTS. Now I have to start its service automatically. manually starting its services working fine, but the issue is when closing the terminal its app stopped working please advise for the best option.

nodejs app.js (working manually)

Thanks in Advance!

Ramesh Chand
  • 7,274
  • 4
  • 33
  • 37

2 Answers2

3

You have to install "forever" service provided by npm package.

forever installation

Using this you can start/stop your project running in background.

Thanks!!!

2

Run:

$ servicename &

Using & causes the program to run in the background, instead of blocking the shell until the program ends.

OR:

Install daemon:

sudo apt-get install daemon

Turn it to a daemon (service)

daemon --name="yourservicename" --output=log.txt sh yourscript.sh

You can also use:

start-stop-daemon -SbCv -x your_command

Source: How to run a program as a service (silent)?

Olimjon
  • 7,292