A
A
Anton Ulanov2016-02-27 13:37:09
Node.js
Anton Ulanov, 2016-02-27 13:37:09

Who implements autostart of node.js applications?

Good time of the day. Who implements the service for starting and restarting a node.js application?
Interested in such features as autorun, restart when it crashes or when the code changes. The simpler the better :)

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Artem Silantiev, 2016-02-27
@AntiStream

This is very easy to do through systemd.
First, we create a service file for our node application of the following type:
# nodeapp.service

[Service]
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodeapp
User=nodeuser
Environment=NODE_ENV=production PORT=3000
WorkingDirectory=/path/to/nodeappdir
ExecStart=/usr/bin/node app.js

[Install]
WantedBy=multi-user.target

Then we do the following in the console:
sudo cp nodeapp.service /etc/systemd/system/nodeapp.service # копируем его куда надо
sudo nano /etc/systemd/system/nodeapp.service # смотрим, [редактируем,] [сохраняем,] закрываем
sudo systemctl daemon-reload # перезагружаем список "демонов"
sudo systemctl start nodeapp # запустить сервис
sudo systemctl enable nodeapp # делаем авто запускаемым при старте системы

# другие действия:
sudo systemctl disable nodeapp # отключаем авто запуск
sudo systemctl stop nodeapp # остановить сервис
sudo systemctl restart nodeapp # перезагрузка
systemctl status nodeapp # посмотреть статус
journalctl -u nodeapp.service # глянуть логи

Everything - this is how it is done on Linux systems, but I don’t know how on Windows, there are my own troubles =))
Well, it is necessary that systemd be installed in the system, on Ubuntu it seems to be available (is) from version 14.10

D
Dmitry Belyaev, 2016-02-27
@bingo347

pm2
Advantages compared to forever,
it can autostart * nix systems, while using all the options that exist today (if system.d is available, it will be added to it, otherwise, depending on the OS, for example, in ubuntu without system.d, sit in init.d)
Done this is one command: pm2 startup
Able to monitor memory and processor load, which is convenient when there is no time to look for a memory leak, and the application should work, it also allows you to monitor all this in real time
Log rotation. Intercepts stdout and stderr, writes logs to a file, makes it possible to connect to the output of the application in real time
Can run applications using other interpreters, as well as just binaries Can run applications
on node in a cluster
Config with launch options in json

V
Vlad Timofeev, 2016-02-27
@PyTiMa

PM2+vps

A
Alexey, 2018-08-19
@azovl

pm2 simple, convenient, high quality

N
Night, 2016-02-27
@maxtm

Through services in Linux, AntiStream gave the correct answer

A
Alexander, 2016-02-27
@w4r_dr1v3r

run through the module foreverIn the end, everything will come down to a command in the console forever restart app.jsThe list of features is available by forever -h
* so that the restart makes sense, do not forget to hang a watcher on the project. supervisorGood luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question