I usually use pm2
to run the server as a service type. It's very simple to use.
npm install pm2@latest -g
To use if it is in the project root, where 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, just monitor the status pm2 status
The logs pm2 logs
and for more information pm2 show <nome da instancia>
or pm2 show index
.
I usually load a 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 / reinitializes it again. In his documentation he explains everything right.
Reference: PM2