Windows or Linux service
In production, the server must restart on its own after an unexpected stop and when the machine starts.
- The service runs
node server.js(the equivalent ofnpm start) from the application folder: the.envfile is read from the current folder. - The
.envfile must containNODE_ENV=production. - When stopping, the server refuses new connections and gives ongoing uploads 10 seconds to finish. The service manager must therefore wait at least 15 seconds before forcing the stop.
- The service account only needs to read the application folder and write to
logs/anddata/.
Windows
With NSSM (adapt the paths):
powershell
nssm install Save2ERP "C:\Program Files\nodejs\node.exe" server.js
nssm set Save2ERP AppDirectory "C:\save2erp"
nssm set Save2ERP AppStopMethodConsole 15000
nssm set Save2ERP AppExit Default Restart
nssm start Save2ERPLinux
With systemd, create the file /etc/systemd/system/save2erp.service:
ini
[Unit]
Description=Save2ERP
After=network-online.target
Wants=network-online.target
[Service]
WorkingDirectory=/opt/save2erp
ExecStart=/usr/bin/node server.js
Restart=on-failure
RestartSec=5
TimeoutStopSec=15
User=save2erp
[Install]
WantedBy=multi-user.targetThen:
bash
systemctl enable --now save2erp
journalctl -u save2erp -fOn Linux, a non-administrator account cannot listen on a port below 1024 (443, for example): use a higher port, or an HTTPS proxy (see Behind an HTTPS proxy).