Skip to content

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 of npm start) from the application folder: the .env file is read from the current folder.
  • The .env file must contain NODE_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/ and data/.

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 Save2ERP

Linux ​

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.target

Then:

bash
systemctl enable --now save2erp
journalctl -u save2erp -f

On 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).