Node app hello.js does not stop with CTRL-C

Hi,

Normally CTRL-C stop the node app.
But the hello.js keeps running. When i try to restart the app with $node hello.js I get the (expected) error:
Error: listen EADDRINUSE: address already in use 127.0.0.1:3000

What am i missing?

6 Replies

It seemed to work with kill -9 [PID id]

But still, why does the normal CTRL-C not work?

After editing hello.js and using $kill -9 [PID id] the node app seems to restart automatically.

This is actually what i want to accomplish with nodemon.
But not like Linode behaves right now: i have no control over the start/restart/stop node proces.

Why does node behave so different on Linode then 'normally' on local machine?

It seemed to work with kill -9 [PID id]

kill -9 is the last resort way to terminate something. It's equivalent to using a lumberjack's axe to swat a mosquito. SIGKILL (signal 9) is the kernel's way of telling a process to eat flaming death with maximum pain. A process cannot handle SIGKILL

But still, why does the normal CTRL-C not work?

Is your app handling signals? If so, have you set up a signal handler for SIGINT that exits the process? That's how CTRL-C works… See:

https://www.geeksforgeeks.org/node-js-process-signal-events/

I don't know anything about node so you'll have to figure this out for yourself.

Why does node behave so different on Linode then 'normally' on local machine?

You have a distorted view of what is "normal"… I could argue that your local machine is doing the wrong thing. Most likely, whatever configuration you have for node on your local machine tells node to do an exit() when a process gets SIGINT

-- sw

Hi SW,

Turns out the default Linode uses a node proces manager (PM2)

This is why the normal CTRL-C command to stop a node app SEEMS to not work: it actually works, but the PM2 restarts the node app automatically.

After stopping the PM2 deamon proces, things work as expected.

I asked the Linode node tutorial to be updated with PM2 info.

Regards,

Marc

After stopping the PM2 daemon process, things work as expected.

You should probably configure the daemon to not do this…or configure systemd to not start the daemon at all (at least temporarily):

sudo systemctl stop the_name_of_the_pm2_daemon_service
sudo systemctl disable the_name_of_the_pm2_daemon_service

To undo this:

sudo systemctl enable the_name_of_the_pm2_daemon_service
sudo systemctl start the_name_of_the_pm2_daemon_service

-- sw

Hi sw,

Ty for your reply.

The basic Linode node 'hello world' example should have mentioned that they use PM2 out of the box.

PM2 i will use later on to easily run multiple node.js servers on a single Linode.
Also, PM2has it own simple commands to start / stop a node server, no need for systemctl etc.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct