0

System: ubuntu 16

I have a working node app on a server. In package.json there is script with options to execute:

 - "start-dev": "cross-env NODE_ENV=development nodemon ./bin/www" 
 - "prod": "cross-env NODE_ENV=production node ./bin/www"
 - "dev": "cross-env NODE_ENV=development node ./bin/www"

What is needed:

  • use a service that would start app on server reboot and generally keep it running all the time (I am using forever now).
  • Start an app as npm script from package.json source from root directory

Right now I can start forever by going to app directory and typing this command:

forever start ./bin/www

but there is no control over the environment.

Additionally, when I try this from root directory - it fails:

forever start /home/myapp/bin/www

How can I start forever from root directory AND using npm script? I assume that initial script should be placed in

/etc/rc.local

Mike Gorski
  • 117
  • 2
  • 13
  • Possible duplicate of [Automatically start forever (node) on system restart](https://stackoverflow.com/questions/13385029/automatically-start-forever-node-on-system-restart) – TomPlum Mar 04 '18 at 10:50
  • Your use case is only for local development or you want a solution for deploy you app on server? – Yahya Mar 04 '18 at 10:50
  • for production use as well – Mike Gorski Mar 04 '18 at 10:51

1 Answers1

1

For deploying on server, You should give pm2 a try.

Advanced, production process manager for Node.js

Yahya
  • 706
  • 8
  • 23