I usually use the pm2
to run the server as a service type. It is quite simple to use.
npm install pm2@latest -g
To use if it is at the root of the project, where the index.js
, mains.js
or server.js
:
pm2 start index.js
To stop is pm2 stop index
or pm2 stop <nome da instancia>
After the start it releases the console so just monitor the status pm2 status
The logs pm2 logs
and for more information pm2 show <nome da instancia>
or pm2 show index
.
Usually I carry one script.json
containing various information such as environment variables, instance name, etc. There are also some commands to save the instance of pm2 and every time the computer or server starts/restarts it again. In his documentation he explains everything.
Reference: PM2