Create service that runs npm start

0

Hello friends of the community.

I have a project made node.js in react and express and I want to deploy it in a virtual machine with ubuntu 16.04 creating a service that runs npm start .

On my pc I run the project with npm start which in turn executes babel-node / bin / www . / bin / www is the project's start script. I execute it on the server in the same way.

The issue is: how can I create a service that runs npm start when the machine starts in the project directory and keeps it active without the need to start it myself.

Thanks

    
asked by José Antonio Pedraza 08.11.2018 в 01:38
source

1 answer

1

The easiest way to do this is using pm2 , so you can manage your processes in nodejs;)

  • Install

npm install -g pm2

  • Run your script

pm2 start npm -- start

  • After having the app running

pm2 save

  • Finally, you generate and run the startup script

pm2 startup

    
answered by 15.11.2018 в 03:38