Email Notifications Driver using Node/sendmail on a PI

YOu have some nodejs server listening on tcp 3000.

1 Like

yep what @aaiyar said!!

node\x20/ 905 pi 13u IPv6 16543 0t0 TCP *:3000 (LISTEN)
1 Like

@jtmpush18

Also - running as user "pi" - so its unlikely to be started by systemd.

OK. I assume that the cast-web-api google assistant relay.

So, I will go and change :slight_smile:
sudo nano /etc/systemd/system/DoNetStuff.service

and change the line:

Environment=PORT=3000

To whatever you want.. ctrl x to exit and y to save

Will that clear it up?

It should - I also noticed that in that file I have

User=adsavia

This should really be

User=pi

or whatever "user" you are using...

1 Like

You might also do a

which npm

To find out the path and make sure in the service file that it is the same.. if not change it.. as well as any other items..

WorkingDirectory=/home/pi/Hubitat-DoNS/DoNetStuff
ExecStart=/usr/bin/npm start

Also remember to change the port # on the HE device end as well!!!

Well:
pi@RASPI:~ $ which npm
/usr/bin/npm

And this is now my configuration:
Unit]
Description=DoNetStuff for Hubitat Service
After=network.target

[Service]
WorkingDirectory=/home/adsavia/Hubitat-DoNS/DoNetStuff
ExecStart=/usr/bin/npm start
Restart=on-failure
User=pi
Environment=PORT=5000

[Install]
WantedBy=multi-user.target

However, it's still not listening on port 5000:
pi@RASPI:~/Hubitat-DoNS/DoNetStuff $ sudo lsof -i -P -n | grep LISTEN
xrdp-sesm 459 root 7u IPv6 12808 0t0 TCP [::1]:3350 (LISTEN)
sshd 506 root 3u IPv4 11532 0t0 TCP *:22 (LISTEN)
sshd 506 root 4u IPv6 11534 0t0 TCP *:22 (LISTEN)
xrdp 508 xrdp 11u IPv6 13918 0t0 TCP *:3389 (LISTEN)
smbd 803 root 33u IPv6 16448 0t0 TCP *:445 (LISTEN)
smbd 803 root 34u IPv6 16449 0t0 TCP *:139 (LISTEN)
smbd 803 root 35u IPv4 16450 0t0 TCP *:445 (LISTEN)
smbd 803 root 36u IPv4 16451 0t0 TCP *:139 (LISTEN)
node\x20/ 905 pi 13u IPv6 16543 0t0 TCP *:3000 (LISTEN)
cupsd 15654 root 9u IPv4 842722 0t0 TCP *:631 (LISTEN)
cupsd 15654 root 10u IPv6 842723 0t0 TCP *:631 (LISTEN)
sendmail- 16341 root 4u IPv4 133876 0t0 TCP 127.0.0.1:25 (LISTEN)
sendmail- 16341 root 5u IPv4 133877 0t0 TCP 127.0.0.1:587 (LISTEN)

!!!wrong work directory!!!

1 Like

the working directory has to be set to your directory.

WorkingDirectory=/home/adsavia/Hubitat-DoNS/DoNetStuff

should be something like this:

WorkingDirectory=/home/pi/Hubitat-DoNS/DoNetStuff

I must not have changed it when I commited it to github. Have now made those changes to be more clear.

1 Like
  1. changed the working directory
  2. npm install
  3. node app.js
    still not working. still same error.
    LISTEN doesn't show port 5000 as per the configuration.

when you run it manually what happens?

sorry like this:

port=5000 node app.js

1 Like

What happens if you try starting it by hand - rather than through systemd, by going to the DoNetStuff directory and running:

node app.js

That's what I'm doing...
pi@RASPI:~/Hubitat-DoNS/DoNetStuff $ node app.js
Created route: /email for controllers/email/index.js
events.js:174
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1280:14)
at listenInCluster (net.js:1328:12)
at Server.listen (net.js:1415:7)
at Function.listen (/home/pi/Hubitat-DoNS/DoNetStuff/node_modules/express/lib/application.js:618:24)
at Object. (/home/pi/Hubitat-DoNS/DoNetStuff/app.js:17:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1307:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

1 Like

apologies - was too slow with my edit..

PORT=5000 node app.js

or

port=5000 node app.js

Maybe that's the issue... in the code it says "process.env.port"

mmmmm

1 Like

@jtmpush18
This should work (just tried on my old Pi B+).

If it doesn't then just edit app.js and change 3000 to 5000.

1 Like
  1. I changed it to
    port=5000 node app.js
  2. npm install
  3. node app.js

same error

Okay I will have to test the code for this..

did you also try uppercase port?

PORT=5000 node app.js

Worst case like @aaiyar said is just change the 3000 to 5000 in app.js but I will look into further.

1 Like

I did change it to upper case, but it appears that didn't do anything.

However, changing the 3000 to 5000 in app.js does seem to have done something.
pi@RASPI:~/Hubitat-DoNS/DoNetStuff $ node app.js
Created route: /email for controllers/email/index.js
Server running on port 5000

However, it just stops with a blank line, and doesn't come back to the prompt.
When I press CTRL C, it does come back. However, with the lof command, it's still not listening on 5000.

Okay cool that's because you are running it directly from the terminal. Try starting with systemctl now..

sudo systemctl start DoNetStuff
1 Like

If, for some strange reason, it won't start with systemctl, then try this:

node app.js &

The & will fork it into the background. So it will keep running. And show up in your lsof command.

Edit - i would first try exactly what @erktrek suggested. This is just a backup suggestion.

1 Like