Viet Le Viet Le - 1 year ago 59
Node.js Question

Port isn't closing when I Exit out of a server

Hello everyone So I have this annoying problem where my port isn't closing. For example I'm using an express generator to give me an outline/skeleton of a node js/express server.

Port 3000 is already in use

Usually I would just able to CTRL + Z and it would exit out the server.

But recently it wasn't exiting out of the server completely.

I found a little work around which was this

lsof -wni tcp:3000

It would then generate something like this

node 5623 viet 12u IPv6 59797 0t0 TCP *:3000 (LISTEN)

I would locate the PID and then kill it with this command

kill -9 5623

But now it just becomes quite annoying doing this over and over everytime I exit out of a server. Does anyone know why its doing this or I guess why CTRL Z wasn't working how It used to.

Answer Source

Ctrl+Z in Unix-based operating systems just suspends the application.

If you do

ps aux|grep node

and then

kill -9 processid

you should be able to reclaim the port.

Going forward, Ctrl+C to shut down the application.