Auto Start Node server on Boot

Post Reply
jasonz
Posts: 1
Joined: Wed Mar 29, 2023 9:44 pm

Auto Start Node server on Boot

Post by jasonz » Wed Mar 29, 2023 9:50 pm

Hi,

I'm currently struggling with auto-starting a node server on boot.

I aim for the device to host a node server and auto-start it by running node server.js command on every boot.

Currently, i have a service file here: /etc/systemd/system/node.service
=== node.service ===
[Unit]
Description=My Node.js App

[Service]
ExecStart=/usr/bin/node /path/to/your/app.js
Restart=always
User=mha
Group=root
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

I have reloaded daemons and enabled the service with
`sudo systemctl enable node.service`

And the log shows that
`Serving at port 3000`

But whenever i try to access 10.0.0.1:3000, it shows:
`Cannot get /`

Any help would be appreciated.

Thank you so much!

nmichael
Posts: 16
Joined: Thu Nov 18, 2021 1:44 pm

Re: Auto Start Node server on Boot

Post by nmichael » Mon Apr 03, 2023 6:17 pm

Is this on the PHL?
I don't know much about node servers, but the Node Red service is set up on the PHL in
/etc/systemd/system/multi-user.target.wants/mahalia-nodered.service

Maybe there are some clues from that configuration?

tobiasherzke
Posts: 119
Joined: Mon Jun 24, 2019 12:51 pm

Re: Auto Start Node server on Boot

Post by tobiasherzke » Fri Apr 07, 2023 5:00 pm

If I understand you correctly, then your log on the PHL shows (1) that your nodejs app has actually started, and (2) that your nodejs app reacts to your connection by logging "Cannot get /". If this is not the reaction that you want, then you need to fix this inside your custom nodejs app, which is a topic not related to openMHA or PHL.

Post Reply