I am learning node js in macOs but I am constantly getting error like
listen EADDRINUSE: address already in use 127.0.0.1:2300<
CodePudding user response:
You need to find the process that's using the port then kill it. To find the process use the following command:
lsof -i -P
The -i
flag displays only IP connections and the -P
flag prints the port as numbers (instead of name, eg 443
instead of https
).
You can filter the result using grep
:
lsof -i -P | grep 2300
The first column is the program/command name and the second column is the process id. For example, if you get the following result:
myProgram 12345 ajit 5u IPv4 0xbb6307766636b4b9 0t0 TCP *:2300 (LISTEN)
You can kill
the process:
kill 12345
CodePudding user response:
First you must to know the PID of what you're looking to kill:
sudo lsof -i :2300
And then kill it with this command:
kill -9 <PID>
PLEASE NOTE: -9 kills the process immediately, and gives it no chance of cleaning up after itself.