Ever since updating to macOS Big Sur version 11.0.1 (20B29), I have been having an issue where my Node.js processes are not being killed when I close the terminal window/tab (ZSH) when the server is started with nodemon. It appears they get switched to a new process, and that new process is kept alive.
For example if run npm run dev, the server starts normally:
...
[nodemon] starting `node dist/index.js`
server started on 5000
In another terminal tab I run lsof -i tcp:5000 and see:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 80310 <user> 27u IPv6 ...99e293 0t0 TCP *:commplex-main (LISTEN)
Then when closing the terminal window running the Node server, I get the same message as prior macOS versions that states the processes in the tab will be terminated:
"Do you want to terminate running processes in this window?
Closing this window will terminate the running processes: npm, node (2)."
I choose 'Terminate', but the server is still accessible on localhost:5000. When I run lsof -i tcp:5000 after closing the Node server tab/window the output shows:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 80625 <user> 25u IPv6 ...8a2293 0t0 TCP *:commplex-main (LISTEN)
So the port stays alive, but with a new PID and new IPv6 for the TYPE.
I should note 2 things:
- If I use Control + C to abort the process, it works as expected.
- As soon as you update a file in the project, the process gets killed.
Has anyone encountered this issue and found a solution?