I run the site on node.js on vds hosting using npm start server.js . Everything works, the console displays logs, others can log in via ip.

If you need to restart the node, you have to restart the entire server and restart the node. On my computer (on windows), I just closed the console.

How to implement a stop and restart node from the console for hosting?

2 answers 2

Use the CTRL + C key combination to stop. And learn how to use screen , I gave you a manual on how to work with it on CentOS, but for other OSs there is also a similar use, the installation is a bit different, but the essence is almost the same.

Create a file run.sh and run through it, it will be convenient in the future, especially when you figure it out normally.

 #Путь до проекта cd /www/test.com/ #Запуск проекта, Test - название процесса screen -S Test npm run start 

You can add the script to autoload, then the server will start immediately after switching on

Specify in packege.json

 "scripts": { "start": "node start server.js" }, 

If you constantly restart the server during development, you can use nodemon , it monitors the files and if something changes, it is restarted

     $ systemctl list-units // Вывод списка юнитов в памяти systemd $ sudo systemctl start NAME... $ sudo systemctl stop NAME... $ sudo systemctl restart NAME...