====== Node.js daemon/service ======
npm install winser
npm install -g pkg
pkg index.js --output myApp.exe
# Use npm_modules/winser/bin/nssm64.exe to create service
Make a myapp.service file (replacing 'myapp' with your app's name, obviously):
[Unit]
Description=My app
After=network.target
[Service]
ExecStart=/var/www/myapp/app.js
Restart=always
User=nobody
# Debian/Ubuntu uses 'nogroup'
# RHEL/Fedora uses 'nobody'
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/myapp
[Install]
WantedBy=multi-user.target
Note: **/var/www/myapp/app.js** should have **#!/usr/bin/env node** on the very first line
Copy your service file into the **/etc/systemd/system**
Start it with **systemctl start myapp**
Enable it on boot with **systemctl enable myapp**
See logs with **journalctl -u myapp**