Node / Express: EADDRINUSE, Address already in use - how can I stop the process using the port?
Asked Answered
O

58

875

I have a simple server running in node.js using connect:

var server = require('connect').createServer();
//actions...
server.listen(3000);

In my code I have actual route handlers, but that's the basic idea. The error I keep getting is:

EADDRINUSE, Address already in use

I receive this error when running my application again after it previously crashed or errors. Since I am not opening a new instance of terminal I close out the process with ctrl + z.

I am fairly certain all I have to do is close out the server or connection. I tried calling server.close() in process.on('exit', ...); with no luck.

Overflight answered 2/11, 2010 at 6:8 Comment(12)
Actually, instead of Ctrl + z you should use Ctrl + c which will close the program correctly by sending SIGQUIT :) See the wiki for further details :)Mammalogy
You mean SIGINT. SIGQUIT is due to `ctrl + \`Baun
use server.close() for previuos serversPersonify
Try pkill nodejs or pkill node if on UNIX-like OSFlaviaflavian
I had a similar issue and found this package that will allow you to exit cleanly when you CTRL+C: npmjs.com/package/exit-hookIdeate
1. Seems like there is a dangling or Dead process ID latched on to the port, So the Node Based service is not starting and throwing error PORT IN USE (ERROR ADDRESS IN USE) 2. We are trying to find out how to release the port 10000 without rebooting the server.Outrigger
I had a kind of similar issue whatever port I set it was showing port already in use ,a simple restart for your desktop/computer solved my problem.hope it helps someoneTrachytic
restarting your computer is a terrible solution.Chevrette
As @Mammalogy said, you should use ctrl + c to close the program. But if you already did ctrl + z, you can use fg to focus on the program again, or use bg to let it resume in the background. Here is a better explanation: superuser.com/a/169057Establishment
it did occur me for couple of time , restarting the system solved the issueRecognizor
My error was caused by something else: My react JS file had "app.listen()" twice.Constable
Only the following worked for me on mac if the popular solutions aren't working for you too! First do lsof -nP -iTCP -sTCP:LISTEN | grep <port>. And then kill -9 <pid>Zuleika
Z
181

process.on('exit', ..) isn't called if the process crashes or is killed. It is only called when the event loop ends, and since server.close() sort of ends the event loop (it still has to wait for currently running stacks here and there) it makes no sense to put that inside the exit event...

On crash, do process.on('uncaughtException', ..) and on kill do process.on('SIGTERM', ..)

That being said, SIGTERM (default kill signal) lets the app clean up, while SIGKILL (immediate termination) won't let the app do anything.

Zenger answered 3/11, 2010 at 10:22 Comment(1)
it's also useful hook on process.on('SIGINT', ... )Gemmagemmate
M
929

First, you would want to know which process is using port 3000

sudo lsof -i :3000

this will list all PID listening on this port, once you have the PID you can terminate it with the following:

kill -9 <PID>

where you replace <PID> by the process ID, or the list of process IDs, the previous command output.

Mezzorelievo answered 20/4, 2017 at 18:30 Comment(16)
This command clearly identifies the PID unlike the output of ps aux | grep node for me. I also did not need sudoGestation
This is the best answer. Worked fine for me with port 8081, using React Native with yarn.Britneybritni
This worked great for me. I could identify where the port 3000 was used and so close it. I also did not need sudo.Thundercloud
Very well. I also tried after getting the command killall -9 {COMMAND} e.g. killall -9 nodeSirup
The command to find a process using a specific port is very useful. So glad you posted this.Tysontyumen
Don't use kill -9 unless you know what you are doing. Basically, try kill PID and kill -2 PID and kill -15 PID and wait a while, and if the process is still around, then bring out the big gun. Killing a process unconditionally doesn't let it do any cleanup, which could lead to file handle leaks and race conditions etc. Or cause the "address already in use" for that matter.Skirt
To find a process on a port in Windows, refer to this thread #48698Artiodactyl
i got this kill: illegal pid: {PID}does anyone could help me?Tony
@Lydia PID is the process number this is just a placeholderMezzorelievo
@MinaGabriel i tried, but has the same error. the port is still occupiedTony
Just to help someone, this is how I used it: PS: The port I wanted to check was 8081. sudo lsof -i :8081 the output of this command showed the PID to be 10074, so I then did: kill -9 10074Smelt
I am getting this same error, however lsof -i :3001 returns an empty result. I have a feeling I have required the app twice or something of that sort, but I can not find where I have. Running with just app.listen() works, but setting a specific port does not.Remonstrant
As a noob the brackets around the PID brought some trouble for me. Folks, you don't need the brackets around the PID. Just type the PID directly.Daynadays
@ChinmayGhule brackets are placeholderMezzorelievo
I edited the answer to make the role of the placeholder clearer.Heelandtoe
This answer helped me to solve the problem!Cusp
W
661

You can also go the command line route:

ps aux | grep node

to get the process ids.

Then:

kill -9 PID

Doing the -9 on kill sends a SIGKILL (instead of a SIGTERM). SIGTERM has been ignored by node for me sometimes.

Wartow answered 22/11, 2010 at 16:36 Comment(9)
What really solved it for me is doing two things. 1. Running my server as a daemon / job. 2. when running within bash, killing the process with ctrl + c. The odd error sometimes causes the app to crash unexpectedly, then I usally 'kill <pid>'Overflight
ps aux | grep node shows nothing; still textareaserver --editor-cmd='gvim -f' fails: 14 Mar 21:19:30 - socket.io ready - accepting connections Could now start the server: EADDRINUSE, Address already in useAleras
Why this rather than killall -9 nodeDebatable
I used this answer for a long time, then one day composed it into a one liner for convenience.. this command will kill any process running on a given port (8000 in this example): lsof -n -i4TCP:8000 | grep LISTEN | tr -s ' ' | cut -f 2 -d ' ' | xargs kill -9Kan
I had multiple node servers running at once, some of them Electron apps. I had to use just kill with the specific process id instead of killall.Cella
Just as a PSA: be very careful with what you kill since many services use Electron and you might inadvertently kill an unrelated process.Dictaphone
Don't use kill -9 unless you know what you are doing. Basically, try kill PID and kill -2 PID and kill -15 PID and wait a while, and if the process is still around, then bring out the big gun. Killing a process unconditionally doesn't let it do any cleanup, which could lead to file handle leaks and race conditions etc. Or cause the "address already in use" for that matter.Skirt
This works, but when there are too many node process running. It becomes harder to sport which process is using which port. Here is a trick on mac os: codegrepper.com/code-examples/shell/… || Actually this is exactly the below answerRunck
please give a solution for windowsCoop
B
301

I hit this on my laptop running win8. this worked.

Run cmd.exe as 'Administrator':

C:\Windows\System32>taskkill /F /IM node.exe
SUCCESS: The process "node.exe" with PID 11008 has been terminated.
Bourgeois answered 8/5, 2013 at 4:10 Comment(7)
I was running it from the Command Window and closed it by accident. Node kept running in the back ground... (even after the session was terminated). In my case once I closed the browser tab that was connected to it via web-sockets it finally terminated.Cletuscleve
taskkill /F /IM node.exe works like a charm for me on Windows from any directory :-) Thanks for the share !!Esoterica
This is the only single-line working solution I've been able to verify for windowsFlexion
Works on windows 10. I didn't have to run the cmd.exe as admin btw.Rectangular
When it says SUCCESS: The process "node.exe" with PID XXX has been terminated. 5 times...Gormand
still getting same error - Socket Error: SocketException: OS Error: Connection timed out, errno = 110, address = 10.1xx.3x.1xx, port = 4xxxx. only on real devices getting this error on emulator working fine.Okay
This is the best answer. The others gave me "command could not be recognized". This just works.Hypothalamus
Z
181

process.on('exit', ..) isn't called if the process crashes or is killed. It is only called when the event loop ends, and since server.close() sort of ends the event loop (it still has to wait for currently running stacks here and there) it makes no sense to put that inside the exit event...

On crash, do process.on('uncaughtException', ..) and on kill do process.on('SIGTERM', ..)

That being said, SIGTERM (default kill signal) lets the app clean up, while SIGKILL (immediate termination) won't let the app do anything.

Zenger answered 3/11, 2010 at 10:22 Comment(1)
it's also useful hook on process.on('SIGINT', ... )Gemmagemmate
Q
148

Check the PID i.e. id of process running on port 3000 with below command :

lsof -i tcp:3000

It would output something like following:

COMMAND  PID   USER   FD   TYPE  DEVICE  SIZE/OFF NODE NAME
node     5805  xyz    12u  IPv6  63135    0t0     TCP  *:3000 (LISTEN)

Now kill the process using :

kill -9 5805
Quicksilver answered 17/11, 2017 at 6:6 Comment(3)
I get no output if I use lost. Does this mean there is no process on that part?Bendicta
Don't use kill -9 unless you know what you are doing. Basically, try kill PID and kill -2 PID and kill -15 PID and wait a while, and if the process is still around, then bring out the big gun. Killing a process unconditionally doesn't let it do any cleanup, which could lead to file handle leaks and race conditions etc. Or cause the "address already in use" for that matter.Skirt
I get no output with lsof... but the issue persists.Brickwork
B
120

For macOS Monterey(12.0):

Apple introduced some changes for AirPlay on macOS Monterey. Now, it uses 5000 and 7000 ports. If you are using these ports in your project, you need to disable this feature.

System Preferences > Sharing > untick AirPlay Receiver


For macOS Ventura(13.0) and above users:

System Settings > General > disable AirPlay Receiver

Bromic answered 29/10, 2021 at 11:46 Comment(2)
It worked friend, just look for "receiver" in MacOS Ventura, because of the interface changeIncinerate
We could also use a different port and leave the feature enabled, goes without saying ;-)Antipole
G
102

I found this solution, try it Give permission use sudo

  sudo pkill node
Gerge answered 25/12, 2016 at 10:21 Comment(1)
I still see node process with this command: ps aux | grep nodeSelfinsurance
B
88

I usually use

npx kill-port 3000

or on my mac.

killall node
Bookstore answered 24/1, 2022 at 2:28 Comment(1)
If you do killall node it is very likely kill also nodejs instances which run for instance react apps.Quilt
H
47

Rewriting @Gerard 's comment in my answer:

Try pkill nodejs or pkill node if on UNIX-like OS.

This will kill the process running the node server running on any port. Worked for me.

Harriot answered 2/11, 2010 at 6:8 Comment(0)
J
41

Linux

Run ps and determine the PID of your node process.

Then, run sudo kill PID

Windows

Use tasklist to display the list of running processes:

tasklist /O

Then, kill the node process like so (using the PID obtained from the tasklist command):

taskkill /pid PID
Jugoslavia answered 3/11, 2010 at 4:36 Comment(3)
And if on Windows?Furlani
Just as a note... for some reason I had to use double slashes on my flags for the taskkill command from git-bash: taskkill //IM node.exe and i just killed node. worked.Malacca
there is no /O argument in the documentation learn.microsoft.com/en-us/windows-server/administration/…Avocado
L
39

For windows open Task Manager and find node.exe processes. Kill all of them with End Task.

enter image description here

Lickerish answered 29/1, 2019 at 4:3 Comment(2)
Update: End Task for "Node.js JavaScript Runtime" is sufficientUrania
It's has been 11 years and still helpful, this is the best answer for windows.Slovak
R
37

Here is a one liner (replace 3000 with a port or a config variable):

kill $(lsof -t -i:3000)
Ricky answered 15/9, 2018 at 6:48 Comment(1)
kill $(lsof -t -i:8080) worked for me when running Node.js Express app with Mongo.Neoplasty
K
23

I was getting this error once and took many of the approaches here.

My issues was that I had two app.listen(3000); calls in the same app.js script. The first app.listen() succeeded where the second threw the error.

Another useful command I came across that helped me debug was sudo fuser -k 3000/tcp which will kill any rogue processes you might have started (some processes may restart, e.g. if run with forever.js, but it was useful for me).

Karajan answered 30/3, 2015 at 2:46 Comment(1)
the same issue here... weird that it was properly working in debugging while getting this error for running npm startDian
P
22

For Visual Studio Noobs like me

You may be running the process in other terminals!

After closing the terminal in Visual Studio, the terminal just disappears.

I manually created a new one thinking that the previous one was destroyed. In reality, every time I was clicking on New Terminal I was actually creating a new one on top of the previous ones.

So I located the first terminal and... Voila, I was running the server there.

multiple terminals withot realizying it

Prehensible answered 10/2, 2019 at 4:6 Comment(0)
T
22

Windows by Cmd

1/2. search => write cmd => open node.js command prompt

enter image description here


2/2. Run windows command: taskkill

Ends one or more tasks or processes.

taskkill /f /im node.exe

/f - force ended

/im - Specifies the image name of the process to be terminated.

node.exe - executable file

enter image description here

Windows - Mannualy by Task Manager

This command is the same as going to Task Manager under the details tab & select node tasks (Tidy in my opinion).

enter image description here

And end task

enter image description here

Visual studio

Sometimes there is more than one terminal/task (client/server and so on). Select and close by ctrl + c.

enter image description here

Thiourea answered 9/3, 2021 at 9:1 Comment(0)
R
20

You may run into scenarios where even killing the thread or process won't actually terminate the app (this happens for me on Linux and Windows every once in a while). Sometimes you might already have an instance running that you didn't close.

As a result of those kinds of circumstances, I prefer to add to my package.json:

"scripts": {
    "stop-win": "Taskkill /IM node.exe /F",
    "stop-linux": "killall node"
},

I can then call them using:

npm run stop-win
npm run stop-Linux

You can get fancier and make those BIN commands with an argument flag if you want. You can also add those as commands to be executed within a try-catch clause.

Rarity answered 20/6, 2019 at 23:36 Comment(0)
B
20

Really simply for all OS's ..

npx kill-port 3000

Although your problem is as mentioned above you need to catch the different ways node can exit for example

process.on('uncaughtException', (err, origin) => {
    console.log(err);
});

// insert other handlers.
Bricebriceno answered 22/9, 2022 at 11:39 Comment(0)
S
18
ps aux | grep node
kill -9 [PID] (provided by above command)

Description:


  1. ps will give the process status, aux provide the list of a: all users processes, u: user own processes, x: all other processes not attached to terminal.
  2. pipe symbol: | will pass the result of ps aux to manipulate further.
  3. grep will search the string provided(node in our case) from the list provided by ps aux.
Scutellation answered 26/7, 2019 at 6:50 Comment(1)
Don't use kill -9 unless you know what you are doing. Basically, try kill PID and kill -2 PID and kill -15 PID and wait a while, and if the process is still around, then bring out the big gun. Killing a process unconditionally doesn't let it do any cleanup, which could lead to file handle leaks and race conditions etc. Or cause the "address already in use" for that matter.Skirt
Y
17

FYI, you can kill the process in one command sudo fuser -k 3000/tcp. This can be done for all other ports like 8000, 8080 or 9000 which are commonly used for development.

Yearling answered 17/5, 2016 at 7:34 Comment(0)
H
16

First find out what is running using:

sudo lsof -nP -i4TCP:3000 | grep LISTEN

You will get something like:

php-fpm 110 root    6u  IPv4 0x110e2ba1cc64b26d      0t0  TCP 127.0.0.1:3000 (LISTEN)
php-fpm 274 _www    0u  IPv4 0x110e2ba1cc64b26d      0t0  TCP 127.0.0.1:3000 (LISTEN)
php-fpm 275 _www    0u  IPv4 0x110e2ba1cc64b26d      0t0  TCP 127.0.0.1:3000 (LISTEN)

Then you can kill the process as followed:

sudo kill 110

Then you will be able to run without getting the listen EADDRINUSE :::3000 errors

Hebner answered 11/12, 2018 at 11:42 Comment(1)
I am using nodemon and it restarts the service again. Is their any way to kill nodemon?Synaeresis
G
15
bash$ sudo netstat -ltnp | grep -w ':3000'
 - tcp6    0      0 :::4000      :::*        LISTEN      31157/node      

bash$ kill 31157
Gustafsson answered 12/5, 2020 at 8:55 Comment(0)
Y
14

PowerShell users:

Taskkill /IM node.exe /F

Yod answered 31/5, 2017 at 20:58 Comment(0)
D
13

UI solution For Windows users: I found that the top answers did not work for me, they seemed to be commands for Mac or Linux users. I found a simple solution that didn't require any commands to remember: open Task Manager (ctrl+shift+esc). Look at background processes running. Find anything Node.js and end the task.

After I did this the issue went away for me. As stated in other answers it's background processes that are still running because an error was previously encountered and the regular exit/clean up functions didn't get called, so one way to kill them is to find the process in Task Manager and kill it there. If you ran the process from a terminal/powerShell you can usually use ctrl+c to kill it.

Dietitian answered 5/3, 2020 at 5:18 Comment(0)
R
9

Task Manager (ctrl+alt+del) ->

Processes tab ->

select the "node.exe" process and hit "End Process"

Regulator answered 17/2, 2016 at 13:6 Comment(2)
why kill the entire node process if what am looking is to kill a node port process .Grimy
That doesn't make sense, there is no separate process for holding the port. If you have several node processes accessing different ports, or none at all, you have to single out the one which is holding on to the port; but it will still be just a node process.Skirt
K
9

Just in case check if you have added this line multiple times by mistake

app.listen(3000, function() {
  console.log('listening on 3000')
});

The above code is for express but just check if you are trying to use the same port twice in your code.

Kittie answered 1/7, 2017 at 7:0 Comment(0)
A
8

On Windows, I was getting the following error:

EADDRINUSE: address already in use :::8081.

Followed these steps:

  • Opened CMD as Admin
  • Ran the folowing

command netstat -ano|findstr "PID :8081"

got the following processes:

enter image description here

killed it via:

taskkill /pid 43144 /f

enter image description here

On MAC you can do like this:

raghavkhunger@MacBook-Air ~ % lsof -i tcp:8081 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 23722 username 24u IPv6 0xeed16d7ccfdd347 0t0 TCP *:sunproxyadmin (LISTEN)

username@MacBook-Air ~ % kill -9 23722

Astraphobia answered 19/1, 2021 at 6:7 Comment(0)
K
7

In windows users: open task manager and end task the nodejs.exe file, It works fine.

Keble answered 3/4, 2020 at 2:39 Comment(0)
D
5

With due respect to all the answers in the form, I would like to add a point.

I found that when I terminate a node app on error using Ctrl + Z, the very next time when I try to open it got the same error EADDRINUSE.

When I use Ctrl + C to terminate a node app, the next time I opened it, it did without a hitch.

Changing the port number to something other than the one in error solved the issue.

Dunno answered 15/3, 2017 at 14:12 Comment(2)
Ctrl + C is the correct. I used the same port number as before and it worked as before.Pouter
<key>Ctrl-Z</key> doesn't stop the process. It puts it in the background so you can run other commands. This is a Unix shell thing. To continue the process use fg in that same console. You can then see what's happening in that server after having typed various commands in the command line.Antimacassar
B
5

using netstat to get all node processes with the port they are using and then kill the only one you want by PID

netstat -lntp | grep node

you will get all node processes

tcp6  0      0 :::5744    :::*    LISTEN     3864/node

and then when you get the PID (3864) just kill the processes by PID

  kill -HUP PID 
Bedraggle answered 3/7, 2021 at 7:10 Comment(0)
P
5

If you are a windows user just go to task manager and end all the task of node jsenter image description here

Pushkin answered 15/10, 2022 at 14:36 Comment(0)
U
4

You may use hot-node to prevent your server from crashing/ run-time-errors. Hot-node automatically restarts the nodejs application for you whenever there is a change in the node program[source] / process[running node program].

Install hot-node using npm using the global option:

npm install -g hotnode

Upi answered 14/9, 2013 at 9:16 Comment(2)
pm2 is a better choice. more robust, more options. and doesn't have the problem when running as root that forever has.Aseity
@Aseity What is this root problem in forever that you speak of? I am unfortunately forced to use forever instead of pm2 on a product at work (due to some licensing crap), and this worries me a lot!Helgoland
B
4

On Linux.

Add function to ~/.bashrc:

function killTcpListen () {
  kill -9 $(lsof -sTCP:LISTEN -i:$1 -t)
}

Pull changes: source ~/.bashrc

And use it: killTcpListen 3000

Benzidine answered 18/9, 2017 at 10:7 Comment(1)
Don't use kill -9 unless you know what you are doing. Basically, try kill PID and kill -2 PID and kill -15 PID and wait a while, and if the process is still around, then bring out the big gun. Killing a process unconditionally doesn't let it do any cleanup, which could lead to file handle leaks and race conditions etc. Or cause the "address already in use" for that matter.Skirt
A
3

Win10, git bash v2.15, node v8.9.1, npm v5.5.1

I had a package.json script to start node: "start": "node index.js"

Whenever I used this, regardless if I killed it with ctrl+c, I ran into this issue.

If I just ran node index.js from git bash instead of npm run start and killed with ctrl+c, I never got this error.

I'm not sure as to why, but I figured this might help someone.

Abana answered 28/11, 2017 at 12:6 Comment(2)
i'm getting the same issue with essentially the same setup. in my case i noticed that running an express app through npm spawns two processes, but only one is closed when using ctrl+c. when starting the app with just node, only one process is open and it closes correctly.Hebetate
this git for windows issue is kind of shedding light on the whole thing. it seems like there might be a bug somewhere between mintty and a cygwin dependency.Hebetate
C
3

server.close() takes a while to close the connection, thus we should make this an asynchronous call as such:

await server.close();

IMPORTANT: when using await, we must use the async keyword in our encapsulating function as such:

async () => {
  await server.close();
}
Columbuscolumbyne answered 17/5, 2019 at 23:56 Comment(0)
K
3

In my case, this problem was caused by the NodeJS environment

Two solutions :

  1. Open Taskmanager and Kill all the Nodejs processes (Name: Node.js JavaScript Runtime)

  2. Try changing the port of your server from 3000 to some other port (say: 3111) that is not currently being used.

Kishke answered 20/3, 2022 at 10:40 Comment(0)
D
3

Modern Windows (powershell)

Current versions of Windows default to using Powershell rather than cmd. Here you'd run:

Get-NetTCPConnection | where Localport -eq 3000 | select Localport,OwningProcess

to find out what the app is.

Dowzall answered 8/6, 2022 at 8:16 Comment(1)
Better and generic way of handling port-in-use issues. Kudos!Confederate
P
2

Node is running somewhere in memory and has that port locked down. On Windows, this problem will happen, like most Windows problems, be solved by hitting CTRL+ALT+DEL and/or rebooting.

Part answered 15/11, 2012 at 15:17 Comment(1)
This question answers so many other questions. Turn it off, and turn it back on again. Genius.Waterfowl
H
2

Use the below command in the terminal/cmd to change the port(npm run dev is for node.js) you may have other commands to run your app most of them will work while changing the port, easier and faster. Furthermore, you can use any port number that is free in your system instead of 3002

PORT=3002 npm run dev

Most of the times when one runs the project while exiting one abruptly or unknowingly presses control + z that gives you exit out of the port always go for control + c that won't exit from port to run the server or project.

Furthermore, its time to change the port number in your code

server.listen(3002);
Harkins answered 6/4, 2020 at 11:48 Comment(0)
D
1

Reasons for this issues are:

  1. Any one application may be running on this port like Skype.
  2. Node may have crashed and port may not have been freed.
  3. You may have tried to start server more than one. To solve this problem, one can maintain a boolean to check whether server have been started or not. It should be started only if boolean return false or undefined;
Diaphane answered 30/8, 2015 at 9:26 Comment(0)
C
1

For all who came to this post and tried all may probably using nodemon or forever to do this. For example if you run PORT=6060 Nodemon You might get the same error that port 6060 is already in use.

If this is the case just run your project without nodemon if you really need to define port during run. Alternatively you can define port in your file itself if you wanna stick to nodemon.

For me I do this now PORT=6060 node app.js

Chico answered 23/3, 2018 at 22:7 Comment(0)
C
1

Simple exit from the server and change the server port 3000 to 31000 and its working fine.

Condom answered 22/4, 2021 at 7:39 Comment(1)
I have no words to explain whats wrong with this answer so downvoted for obvious reasons.Bricebriceno
L
1

Try to changing port number. It worked for me. For example you can change the port number from 3000 to 3001.

Linnealinnean answered 16/9, 2021 at 12:33 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Brennan
F
1

I'm using Windows 10 and I'm on the development of React Native project when I encountered this problem.

To solve this,

Type npx kill-port portName. like in my case, it was npx kill-port 8081, and hit enter.

After that, run this command to check whether your port is empty or not.

adb reverse tcp:8081 tcp:8081.

If port 8081 is still busy, it will pop-out to the terminal, otherwise, you're good to go to run npm start

Foreigner answered 1/6, 2023 at 12:59 Comment(0)
K
0

This means you have two node servers running on the same port ,if one is running on port let say 3000 change the other one to another port lets say 3001 and everything will work well

Koehler answered 16/11, 2016 at 8:6 Comment(0)
B
0

I wonder, why nobody yet mentioned this possibility:

  • If you provide ::listen(port) with string (intentionally or not), which wouldn't be a valid port number representation, it then can be internally converted to port number -1, ant then engine will try to connect to that -1 port, which then yields the same EADDRINUSE error, which in turn might be slightly confusing and turn you in the wrong direction for error fix search (hi, me xD).

So, debug your code and check what exactly you pass to functions, before starting to check for the processes, that are using your port.

Briony answered 4/7, 2017 at 5:27 Comment(0)
P
0

In my case, it was because I have Eclipse open...

Philis answered 8/5, 2019 at 19:41 Comment(0)
A
0

Kill only node process that uses given PORT. As others mentioned, in bash you could use kill $(lsof -t -i:PORT)

Here is a Windows solution (there's a way!): netstat -bona | findstr ".0:PORT +0.0.0.0:0 +LISTENING" | for /f "tokens=5" %t in ('more') do taskkill /PID:%t /F. You need an elevated terminal for that (in VSCode you'll need to open itself with elevation, as integrated terminal cannot be elevated).

PS: if findstr not available, you can simply use find and replace " +" for spaces (non regex mode)

Anta answered 15/6, 2019 at 5:46 Comment(0)
I
0

I had the same problem and I found out that it was the nodemon problem. First I was using this script to start my process:

{"dev": "nodemon -r dotenv/config app.js"}

the app boots correctly, but as soon as any file changes, nodemon can't restart it. In the meantime, the app still continues to run in the background. If I do Ctrl+C, it quits, but there's no more process on port 3000, so killing it by port fuser -k 3000/tcp doesn't do anything.

And, I was using .env port in app.js file.

const port = process.env.PORT || 3000;

So, I changed the port value to 3000 only and it worked.

const port = 3000;

I had to find another way to load .env file, but this solved the issue for me. Hope that helps.

Indention answered 7/5, 2020 at 17:56 Comment(0)
T
0

I was facing the same problem. I just changed my port number from 8000 to 6000. as you have 3000 you try 5000,4000,7000,8000 etc.

Tricorn answered 7/9, 2020 at 17:10 Comment(0)
H
0

An easy way is to list all the processes that are listening on your port

lsof -i tcp:YOUR_PORT | grep LISTEN

Then you can kill them :

kill -9 {PID}

Haematosis answered 9/1, 2023 at 11:15 Comment(0)
P
0

For Linux/ubuntu

npx kill-port 3000 or

npx kill-port 4000 or

npx kill-port 8000 

Whichever post you are using

Like

app.listen(4000, () => {
  console.log('Listening on 4000');
});
Pushkin answered 8/4, 2023 at 10:14 Comment(1)
npx kill-port 3000 worked for me!Paschall
V
-1

I had another problem. I had declared the port twice. Don't do that mistake as well.

app.listen(port, function () {
  console.log('Example app listening on port')
})

app.listen(3000, function() {
  console.log("Server started on port 3000");
});

Instead do this:

const port = 3000;

app.listen(port, function () {
  console.log('Example app listening on port')
})
Verdha answered 23/3, 2021 at 4:40 Comment(0)
S
-1

Maybe another your project scripts is running !

Make sure no other scripts are running, such as "start" !!!

Sisley answered 30/8, 2023 at 13:22 Comment(0)
Q
-1

In linux and Mac

If you are in the same terminal session, just type: fg, which stands for foreground, in order to comeback to foreground again the app instance and simple kill it as usual.

Quilt answered 4/9, 2023 at 15:29 Comment(2)
The huge assumption you are making here is that the process doing the blocking is running in the background of the same terminal session.Kolva
That is right, as I stated in the response. "if you are in the same terminal session..."Quilt
T
-2

This command list the tasks related to the 'node' and have each of them terminated.

kill -9  $( ps -ae | grep 'node' | awk '{print $1}')
Tremendous answered 15/9, 2016 at 20:50 Comment(0)
P
-2

delete undefined file in your project root directory (which created on app crash)

Potvaliant answered 13/8, 2020 at 14:3 Comment(0)
C
-2

I was using debugger and just not stopped the processes running with Ctrl+C. So when I wanted to start debugging I got this error.

Cantilena answered 17/9, 2020 at 19:18 Comment(0)
T
-2

This happend to me, because I had multiple instances of visual studio open in my ubuntu without noticing it and there was xdebug already running in one of them.

Teerell answered 11/3, 2022 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.