I am trying to continuously run a nodeJs server on my VPS, I made a systemdservice and started it.

I worked by my server is still not accessible, I can check the status and it works Okey :

Service Status :

Node.service - Runs the Node Server for Node API
   Loaded: loaded (/etc/systemd/system/Node.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-05-12 16:16:38 CEST; 2min 37s ago
 Main PID: 26697 (node)
    Tasks: 10
   Memory: 87.5M
      CPU: 2.734s
   CGroup: /system.slice/Node.service
           └─26697 /root/.nvm/versions/node/v9.11.1/bin/node www

May 12 16:16:38 vps543107 systemd[1]: Started Runs the Node Server for Node API.
May 12 16:16:41 vps543107 node[26697]: Listening on port 3000

Service :

Description=Runs the Node Server for Node API
Documentation="No Docs"

ExecStart=/root/.nvm/versions/node/v9.11.1/bin/node www


I can't get to the server via any HTTP request, all requests timeout.

Is there a problem with my Service.

  • 1
    Looks good to me. My guess would be the firewall, since you got as far as the "listening" message. (I assume it also doesn't work if you start the process by hand?) – Ulrich Schwarz May 12 '18 at 15:43
  • I am not actively using a firewall, and it works when launched by hand. – Kaki Master Of Time May 14 '18 at 7:51

Try following

Description="Runs the Node Server for Node API"
#Requires=After=mysql.service       # If you have any dependency then add it

ExecStart=/root/.nvm/versions/node/v9.11.1/bin/node /root/Node/bin/www
# Restart service after 10 seconds if node service crashes

# Output to syslog
#Change this to find app logs in /var/log/syslog
# Followig will require if you are using the PORT or Node from Envirnoment
Environment=NODE_ENV=production PORT=3000


Once your server machine is up & you are not able to access server, you troubleshoot by checking logs from /var/log/syslog by the following command

sudo cat /var/log/syslog | grep -r "nodejs-api"

Start on boot: sudo systemctl enable rocketchat

| improve this answer | |

Start your app with After=network-online.target to make sure the network is fully up before you start it.

You mention that the app is not not available over "HTTP". Did you intent to run the app on port 3000 on your server port 80, the default HTTP port? Are you testing it on the same port you are running it on?

Running your app with User=root is a security risk. A security flaw in your web app could directly lead to the full compromise of your VPS. Consider running your app as an unprivileged user to mitigate that risk.

If you the app to start at boot, make sure you have used systemctl enable your-app to enable it to start at boot.

Also, I see you are using NVM. It appears to be working based on your service status, but is not my recommendation for production services. It depends on environment variables, which makes it more fragile.

I recommend using the n package manager instead for production instead, which uses only symlinks to switch versions, and no environment variables.

Also see the FAQ answer for why things don't work under system when they start manually.

| improve this answer | |
  • I intend it to work on the 3000 port. and yes I am testing it on that port too. The server starts correctly if I launch it manually. – Kaki Master Of Time May 16 '18 at 7:45
  • @KakiMasterOfTime I updated my answer to address the fact that it works manually but not under systemd. – Mark Stosberg May 16 '18 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.