130

i am testing a server written in nodejs on windows 7 and when i try to run the tester in the command line i get the following error

Error: listen EADDRINUSE
at errnoException (net.js:614:11)
at Array.0 (net.js:704:26)
at EventEmitter._tickCallback (node.js:192:40)

how can I fix it without rebooting?

adam
  • 1,423
  • 2
  • 11
  • 14

30 Answers30

169

Run:

ps -ax | grep node

You'll get something like:

60778 ??         0:00.62 /usr/local/bin/node abc.js

Then do:

kill -9 60778
Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
Komposr
  • 1,946
  • 1
  • 12
  • 4
101

It means the address you are trying to bind the server to is in use. Try another port or close the program using that port.

fent
  • 17,861
  • 15
  • 87
  • 91
  • I couldn't find anything using port 3000, but changing it worked! – Dennis Nov 10 '12 at 23:56
  • 8
    Since this single node program is the only thing using port 3000 on my machine, it seems pretty clear that something has happened to prevent the previous instantiation of my node process from shutting down properly. It was working when I used `node app.js` and stopped it with Ctrl+C, but started having the EADDRINUSE issue after the first time I used `npm start`, so it seems the real solution would be to use something other than Ctrl+C to shut down after using `npm start`. – David Mason May 11 '13 at 23:43
  • Your `npm start` script might be more than one node program, or a node program that is ran in the background, or the program might have child processes who use that port. – fent May 12 '13 at 03:33
  • 2
    Very often, this error happens because of a node-process has not jet been terminated. But sometimes the port is in use by other processes, and therefore it might be difficult to understand/locate the correct process blokking it. WolfReporter below has a correct solution to this problem! http://stackoverflow.com/a/22875192/36975 – qualbeen Jun 21 '15 at 19:25
  • 6
    I did `ps aux | grep node`, find the process id (second column) and simply kill it with `kill ` (mine was `kill 18762`). – nik_m Feb 06 '18 at 14:46
  • if he could use another port, why is he asking? – Aladdin Mhemed May 25 '18 at 21:25
42

On Linux (Ubuntu derivatives at least)

killall node

is easier than this form.

ps | grep <something>
kill <somepid>

Neither will work if you have a orphaned child holding the port. Instead, do this:

netstat -punta | grep <port>

If the port is being held you'll see something like this:

tcp           0      0.0.0.0:<port>          0.0.0.*       LISTEN     <pid>/<parent>

Now kill by pid:

kill -9 <pid>
WolfReporter
  • 537
  • 4
  • 3
35

The following command will give you a list of node processes running.

ps | grep node

To free up that port, stop the process using the following.

kill <processId>
wcurtis
  • 359
  • 4
  • 4
  • 3
    You might want to add a `| grep -v grep` to exclude the `grep` process. – Garrett Hyde Nov 24 '12 at 21:17
  • 6
    As the original poster wrote: "on windows 7" ... ;-) – Golo Roden Nov 24 '12 at 22:18
  • 4
    A much better alternative would be `pidof node` – Itay Grudev Feb 23 '13 at 01:12
  • `pidof` was easily installed for me on osx with homebrew `brew install pidof` – electblake Apr 05 '13 at 05:13
  • 1
    If you are running more then just node applications it's possible that the address is bound to some other application. Wouldn't it be better to search for the pid that is bound to the port you're trying to start up on? ie: for linux you could use netstat -lnptu | grep port#. Not sure what the equivalent for windows is. – chrisst Sep 03 '13 at 17:04
32

You are getting the error EADDRINUSE because the port, which your application wants to use, is occupied by another process. To release this port, you need to terminate the occupying process.

Since you are on Windows, you can terminate the process using the command prompt (cmd). With the cmd you can discover the process ID (PID) of the blocking application. You will need the PID in order to terminate / kill the process.

Here is a step-by-step guide...

  1. Find all processes which are running on a specified port (in this example, Port is "3000"):

    netstat -ano | find ":3000 "

  2. The netstat command will list up all processes running on the specified port. In the last column of the netstat results you can see the PIDs (in this example, PID is "8308"). You can find out more about a specific PID by running the following command:

    tasklist /fi "pid eq 8308"

  3. If you want to terminate a process, you can do that with the following command by using its PID (in this example, PID is "8308"):

    taskkill /pid 8308 /f

Screenshot

enter image description here

Benny Code
  • 51,456
  • 28
  • 233
  • 198
20

When you get an error Error: listen EADDRINUSE,

Try running the following shell commands:

netstat -a -o | grep 8080
taskkill /F /PID 6204

I greped for 8080, because I know my server is running on port 8080. (static tells me when I start it: 'serving "." at http://127.0.0.1:8080'.) You might have to search for a different port.

Michael Scheper
  • 6,514
  • 7
  • 63
  • 76
swathy valluri
  • 5,039
  • 2
  • 16
  • 13
  • 1
    At last! An answer that searches by port, instead of by process. It's not just node that can tie up a port! – Michael Scheper Sep 14 '16 at 20:07
  • I produced a module to detect which running process is locking a port, called [porthog](https://github.com/coreybutler/porthog). It basically executes the code above. – Corey Sep 15 '16 at 14:03
17

suppose your server is running on port 3000

lsof -i tcp:3000
    COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    node    11716 arun   11u  IPv6 159175      0t0  TCP *:3000 (LISTEN)

after that use kill -9 <pid>

in the above case sudo kill -9 11716

Arun Kasyakar
  • 905
  • 8
  • 9
13

use below command to kill a process running at a certain port - 3000 in this example below

kill -9 $(lsof -t -i:3000)
Dmitriy
  • 5,525
  • 12
  • 25
  • 38
Atta Ur Rahman
  • 131
  • 2
  • 4
7

One possible solution that worked for me was simply to close the window in browser where I had the corresponding "http://localhost:3000/" script running.

iloo
  • 926
  • 12
  • 26
6

When you get an error

Error: listen EADDRINUSE

Open command prompt and type the following instructions:

netstat -a -o | grep 8080
taskkill /F /PID** <*ur Process ID no*>

after that restart phone gap interface.

If you want to know which process ID phonegap is using, open TASK MANAGER and look at the Column heading PID and find the PID no.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Eshan Chattaraj
  • 368
  • 1
  • 6
  • 19
6

Check the Process ID

sudo lsof -i:8081

Than kill the particular Process

sudo kill -9 2925

enter image description here

Surender Kumar
  • 1,152
  • 16
  • 17
  • this saved me...learned not to run Docker if you don't know what you're doing. None of the other suggestions worked because of node being containerized. – Zack Biernat Jan 27 '21 at 18:15
5

The aforementioned killall -9 node, suggested by Patrick works as expected and solves the problem but you may want to read the edit part of this very answer about why kill -9 may not be the best way to do it.

On top of that you might want to target a single process rather than blindly killing all active processes.

In that case, first get the process ID (PID) of the process running on that port (say 8888):

lsof -i tcp:8888

This will return something like:

COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node     57385   You   11u  IPv6 0xac745b2749fd2be3      0t0  TCP *:ddi-tcp-1

(LISTEN) Then just do (ps - actually do not. Please keep reading below):

kill -9 57385
Fullstack Guy
  • 16,368
  • 3
  • 29
  • 44
5

This works on Mac:

Step 1.

sudo lsof -i tcp:3000 (or whatever port you want to kill)

Above command will give you the Process Id(s) currently holding the port.

Step 2.

Kill -9 <pid>
saran3h
  • 12,353
  • 4
  • 42
  • 54
3

you can change your port in app.js or in ur project configuration file.

default('port', 80)

and to see if port 80 is already in use you can do

netstat -antp |grep 80

netstat -antp |grep node

you might wanna see if node process is already running or not.

ps -ef |grep node

and if you find its already running, you can kill it using

killall node

Adeel Ahmad
  • 1,671
  • 1
  • 17
  • 22
1

I created 2 servers, listening on same port 8081, running from same code, while learning

1st server creation shud have worked 2nd server creation failed with EADDRINUSE

node.js callback delays might be reason behind neither worked, or 2nd server creation had exception, and program exited, so 1st server is also closed

2 server issue hint, I got from: How to fix Error: listen EADDRINUSE while using nodejs?

Community
  • 1
  • 1
Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
1

Error: listen EADDRINUSE to solve it in Ubuntu run in terminal netstat -nptl and after this kill -9 {process-number} this command is to kill node process and now you can try to run again node server.js command

Ex

listen EADDRINUSE :::8080

netstat -nptl

tcp6 0 0 :::9000 :::* LISTEN 9660/java
tcp6 0 0 :::5800 :::* LISTEN -
tcp6 0 0 :::5900 :::* LISTEN -
tcp6 0 0 :::8080 :::* LISTEN 10401/node
tcp6 0 0 :::20080 :::* LISTEN 9660/java
tcp6 0 0 :::80 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::10137 :::* LISTEN 9660/java

kill -9 10401

navnit kapadiya
  • 179
  • 1
  • 1
  • 9
  • 2
    User said it's on Windows. On Windows `netstat` receives different parameters. `netstat -a -p tcp -b -v` would output the process name. – arboreal84 May 17 '17 at 05:46
0

I have node red installed on my Mac and my Raspberry Pi. Had the exact same problem and doing 'killall' didn't help. Once I shut down the Raspberry Pi and restarted my computer it worked fine.

alkopop79
  • 547
  • 12
  • 28
0

It may be possible that you have tried to run the npm start command in two different tabs .you cant run npm start when it is already running in some tab.check it once .

0

To anyone who has tried all of the above, but still can't find the rouge process, try them all again but make sure you include "sudo" in front of the commands.

MMMTroy
  • 1,256
  • 1
  • 11
  • 20
0

If you like UI more, find the process Node.js in windows task manager and kill it.

polina-c
  • 6,245
  • 5
  • 25
  • 36
0

ps -ef |grep node find app.js , kill pid of app.js

megan5
  • 11
  • 1
0

simply kill the node as pkill -9 node in terminal of ubantu than start node

0

You will need to kill the port by trying to use the following command on the terminal

$ sudo killall -9 nodejs
Shivam Kohli
  • 449
  • 4
  • 6
0

It's might be too late but it's working like a charm.

You need pm2 to be installed

npm install -g pm2

To stoping the current running server (server.js):

pm2 stop -f server.js
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Kapta
  • 1,525
  • 14
  • 24
0

I have solved this issue by adding below in my package.json for killing active PORT - 4000 (in my case) Running on WSL2/Linux/Mac

"scripts": {
    "dev": "nodemon app.js",
    "predev":"fuser -k 4000/tcp && echo 'Terminated' || echo 'Nothing was running on the PORT'",
  }

Source

zashishz
  • 377
  • 4
  • 6
0

I Just delete that (cmd) Terminal and open another terminal and run again node myfile.js

it works awesomely for me.

0

It's year 2022 now and I am on Monterey (Mac user).

enter image description here

lsof -i tcp:3000
Kill -9 <PID shown in your list>
Kelvin Fok
  • 621
  • 7
  • 9
-1

To kill node server first run this command in your terminal :

  1. top
  2. open another window then copy the server id from the previous window: PID number -9 kill so now you killed your node server try again to run your app.
fewlinesofcode
  • 3,007
  • 1
  • 13
  • 30
-1

I used the command netstat -ano | grep "portnumber" in order to list out the port number/PID for that process. Then, you can use taskkill -f //pid 111111 to kill the process, last value being the pid you find from the first command.

One problem I run into at times is node respawning even after killing the process, so I have to use the good old task manager to manually kill the node process.

davida227
  • 19
  • 1
-4

In window, please execute this command:

taskkill /F /PID 1952
codingEnthusiast
  • 3,800
  • 2
  • 25
  • 37
thinhnk
  • 351
  • 3
  • 12