﻿{"id":366,"date":"2022-04-29T13:03:52","date_gmt":"2022-04-29T10:03:52","guid":{"rendered":"https:\/\/xn--e1agicip.xn--90ais\/?p=366"},"modified":"2023-06-14T13:37:31","modified_gmt":"2023-06-14T10:37:31","slug":"node-js-as-service","status":"publish","type":"post","link":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/2022\/04\/29\/node-js-as-service\/","title":{"rendered":"\u0417\u0430\u043f\u0443\u0441\u043a node.js \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a\u0430\u043a \u0441\u043b\u0443\u0436\u0431\u044b"},"content":{"rendered":"\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432 \/etc\/systemd\/system\/nodeserver.service<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\nDescription=My node Server\n\n&#91;Service]\n# set the working directory to have consistent relative paths\nWorkingDirectory=\/var\/www\/app\n\n# start the server file (file is relative to WorkingDirectory here)\nExecStart=\/home\/user\/.nvm\/versions\/node\/v14.15.3\/bin\/node .\/src\/index.js\n# if process crashes, always try to restart\nRestart=always\n\n# let 500ms between the crash and the restart\nRestartSec=500ms\n\n# send log tot syslog here (it doesn't compete with other log config in the app itself)\nStandardOutput=syslog\nStandardError=syslog\n\n# nodejs process name in syslog\nSyslogIdentifier=nodejs\n\n# user and group starting the app\nUser=www-data\nGroup=www-data\n\n# set the environement (dev, prod\u2026)\nEnvironment=NODE_ENV=production\n\n&#91;Install]\n# start node at multi user system level (= sysVinit runlevel 3) \nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c, \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service nodeserver start\nservice nodeserver stop\nservice nodeserver restart<\/code><\/pre>\n\n\n\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c systemd \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0443\u0437\u0435\u043b \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0432\u0435\u0434\u0438\u0442\u0435:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl enable nodeserver<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432 \/etc\/systemd\/system\/nodeserver.service \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c, \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e: \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c systemd \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0443\u0437\u0435\u043b \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0432\u0435\u0434\u0438\u0442\u0435:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[83,84,82,85],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts\/366"}],"collection":[{"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":2,"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":368,"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/posts\/366\/revisions\/368"}],"wp:attachment":[{"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xn--e1agicip.xn--90ais\/index.php\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}