Page 1 of 1

Auto Start Node server on Boot

Posted: Wed Mar 29, 2023 9:50 pm
by jasonz
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!

Re: Auto Start Node server on Boot

Posted: Mon Apr 03, 2023 6:17 pm
by nmichael
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?

Re: Auto Start Node server on Boot

Posted: Fri Apr 07, 2023 5:00 pm
by tobiasherzke
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.