Node.js Port 3000 already in use but it actually isn't?
Solution 1
You can search on how to kill that process.
For Linux/Mac OS search (sudo) run
this in the terminal:
$ lsof -i tcp:3000
$ kill -9 PID
On Windows:
netstat -ano | findstr :3000
tskill typeyourPIDhere
change tskill
for taskkill
in git bash
Solution 2
Maybe you can take this as reference. This single command line can kill the process running on given port.
npx kill-port 3000
To kill multiple ports.
npx kill-port 3000 8080 4200
Solution 3
Sometimes it happens, as @sova proposed This happens to me sometimes, EADDR in use. Typically there is a terminal window hiding out in the background that is still running the app. And that's also right with me.
It happens, when you have opened terminal for long time, yeah you have right, you have stop the process. But sometimes it didn't stop in the background. So best solution is that you close the terminal and start it again. It will solves your problem. becuase in my case it works.
Also,
sudo lsof -i:<PORT_NO>
close the instance for present time but unable to stop the process in background. So for one time,
sudo kill <PID>
works, but again when we update our code and save, this problem occurs again as with Nodemon.
So exit the terminal will solve the problem. OR
killall -9 node
Solution 4
I also encountered the same issue. The best way to resolve is (for windows):
-
Go to the Task Manager.
-
Scroll and find a task process named. Node.js: Server-side JavaScript
-
End this particular task.
There you go! Now do npm start and it will work as before!
Solution 5
I had the same problem. (The below steps work fine on Windows 10):
- Open Task manager (press Ctrl+Alt+Delete)
- Select the 'Processes tab'
- Search for 'Node.js: Server-side JavaScript'
- Select it and click on 'End task' button
Now you can run npm start
.
Hope it helps you.
Related videos on Youtube
user2573690
Updated on August 01, 2022Comments
-
user2573690 almost 2 years
I have been working with a node.js project for a few weeks and it has been working great. Usually, I use
npm start
to run my app and view it in a browser on localhost, port 3000.Today, I started to get the following error while using npm start:
Server started on port 3000 Port 3000 is already in use
I have checked the resource monitor and I have no other process running on port 3000. Why would I be getting this error message?
In my app.js I have the following code to set the port...is this incorrect? It worked fine before so I'm not sure what I am doing wrong.
// Set Port app.set('port', (process.env.PORT || 3000)); app.listen(app.get('port'), function() { console.log('Server started on port '+app.get('port')); });
Thanks for the help!
EDIT:
I have tried running netstat and TCPView to check what process is using the port, but there is nothing using that port. I also tried restarting my laptop but I still get the same error.
-
tanaydin over 7 yearsThere is another process that uses this port, it is certain. Which os are you trying to ? You can google it like 'find which prosess uses port' for your operating system
-
Blorgbeard over 7 yearsHave you tried browsing to localhost:3000 ?
-
user2573690 over 7 years@tanaydin I have checked Resource Monitor on Windows 10 and there is no process listening on port 3000. Unless its one that I cannot see?
-
Isaac over 7 yearshave you tried stackoverflow.com/questions/48198/…
-
user2573690 over 7 years@Blorgbeard nothing comes up, "Site can't be reached" however, on the Chrome tab I see the favicon of my node site...but the app itself isn't running
-
Blorgbeard over 7 yearsThe favicon will be cached. You could also try
netstat
in a command prompt, or connecting to localhost:3000 with a telnet equivalent - PuTTY, for example. -
Blorgbeard over 7 yearsAnd of course, this might work..
-
user2573690 over 7 years@Blorgbeard I tried TCPView and netstat and there is nothing running on port 3000, I also tried restarting my laptop and still the same issue.
-
Blorgbeard over 7 yearsI notice you get "Port 3000 is already in use" after "Server started on port 3000" - is something in your app attempting to start listening again on the same port?
-
user2573690 over 7 years@Blorgbeard I checked the npm-debug log and I noticed that there is an error "Tell the author that this fails on your system: node ./bin/www"
-
Josh Beam over 7 yearsPossible duplicate of Node / Express: EADDRINUSE, Address already in use - Kill server
-
Josh Beam over 7 yearsMarked as dupe, try:
ps aux | grep node
thenkill -9 PID
-
jfriend00 over 7 yearsMy guess is that you have two
app.listen()
statements in your app on another.listen()
that is also trying to start a server on that port. The first one works, the second one reports the error. Search your code for.listen
. -
Steve Bennett over 7 yearsSounds a lot like you have a bug in your start up code. Maybe add or link more of your code and someone will find it?
-
SMEETT over 2 yearsFor me it was my
.env
- so make sure there are no syntax errors there.
-
-
user2573690 over 7 yearsThanks for the help! I don't have any other terminal windows open, anything else I should check?
-
sova over 7 yearsfind any node or npm process and end it. if still you have a funk, reboot machine, or just pick a different port to work with. There's really no reason it must be port 3000 or 8080
-
user2573690 over 7 yearsI just created a new node app and started it on port 3000 and that one seems to work fine, but when I try to run my existing project, it says the port is in use. Have you ever had this issue?
-
sova over 7 years@user2573690 i have not come across that before, but maybe you have multiple js files (like an app.js and an index.js) where one is calling
.listen()
multiple times? -
user2573690 over 7 yearsThank you! I managed to figure it out, I was listening to the port multiple times, copy/pasta accident! If you can edit your answer and add that piece, I will mark it. Again, thank you!
-
Cody almost 7 yearsHere's a weird issue: I've
Ctrl+C
'd (^C) out of the process in GitBash, but when I hoist the server again --npm start
-- then I get the EADDR in use. When I refresh my browser, I see all theGET
logs that indicate the thread is still running. This usually happens if I've slept my laptop and come back. If I'm lucky, closing out all instances of GitBash and waiting a minute seems to do the trick, though, its a pain shutting down different instances across multiple git projects/servers. -
Cody almost 7 years[SEE ABOVE] I just had experiment: I shutdown (
Ctrl+C
) my server and waited about the same amount of time it takes me to shutdown all my GitBash instances before hoisting the server again -- that seems to have made the difference. Hope this saves you time. -
Julsteri about 6 yearsNeither the lsof or netstat returned anything, yet there still seemed to be some process using the port. After
killall -9 node
I was able to run the server locally. -
truedat101 over 5 yearsI've tried a number of other solutions on windows, but this one found the odd process that was hogging the port. Earned an upvote for including also the linux approach in addition to working on windows.
-
snersesyan over 5 yearstskill didn't working for me on windows. taskkill /F /PID myPIDhere - this working
-
user985366 almost 5 yearsI get nothing with only
lsof
but withsudo lsof
I get something, and killing that process solved this problem. -
Kalkhas almost 5 yearsAdjust the delay as required.
-
S_W over 4 yearsIs there a way to dynamically get the PID for the running process and kill it? For some reason, I have to do this every time I deploy to prod manually. Side note, sure if this is related to PM2 or not.
-
Titou over 4 yearsupvoted for the willingness to help AND a solution that may help find the root cause.
-
Nathan over 4 yearsI just had this happen to me as well.
netstat -ano
didn't list anything using port 3000. -
3Dos over 4 yearsHoly hell, this solved it for me too as obviously nothing was running on port 3000. I started having this issue after a Windows update. Never thought about turning WiFi off. Thank you for solving this :)
-
twknab over 4 yearsThis is quite a nice and clean solution to killing a process. Have to look how to do this up every time, and this is the nicest solution I've seen yet!
-
xaunlopez over 4 yearsIm experiencing this issue although no processes are returning from
lsof -i :3000 -t
=\ -
ifhy about 4 yearsthanks for the killall -9 node command. it worked on goorm IDE
-
nickcamillo about 4 yearstaskkill did not work for me on git-bash, but tskill did. thanks.
-
Afeesudheen almost 4 years@xaunlopez try this one
fuser -k port-number/tcp
-
Deep Roy almost 4 yearsworked for me just had to add the PID displayed from the "lsof -i tcp:3000" command
-
vibhor vaish almost 4 yearsWould have even better if you had explained the commands in detail too but stackoverflow is life saving.
-
Hrishikesh Baidya over 3 yearsGreat solution Thanks a ton.
-
Bergi over 3 yearsWhat does
kill-port
do? How does it work? -
Mohammad Hossein Ganjyar over 3 years@Bergi It kill its port that you want run for app
-
Bergi over 3 yearsNo, it doesn't. A port cannot be killed.
-
Mohammad Hossein Ganjyar over 3 years@Bergi you should read its document, please.
-
Bergi over 3 yearsPlease put the relevant parts in your answer as well.
-
Manuel Cheța over 3 yearsAwesome. Thanks.
-
Ben Alan over 3 yearsI killed the process, but another one immediately started with a different PID, also using port 3000
-
Amit Khanna about 3 years
npx kill-port 3000
worked for me. Thanks @Penny -
Herman Van Der Blom about 3 yearsYou are the Greatest :-) The line: "stop": "taskkill -f -im node.exe" in the package.json did it for me. I work remote with SSH. I had to look for a solution I think more as one Hour. All the kill commands etc. did not work.
-
Snowcat almost 3 yearsI had the same error on Ubuntu so what helped me was 1) make sure you haven't already assigned Port to a variable and are still using quotes ("port") to get your port connection instead of the variable. Secondly, on Ubuntu you can use Run sudo netstat -lp to figure out what is using that port
-
shailesh gavathe almost 3 yearsfor me this helped. I had turned on wifi at some point in the day. I usually use the Ethernet. So i completely cut off wifi and then rebooted it. Everything back to working again. Wow. Without your hint, I would have been wondering off for hours maybe.
-
Xairoo almost 3 years
net stop winnat
- I just forgot that command. Needed it a few weeks ago and today because of the same problem (appears sometimes... why?!). Will add this to autostart. -
towith almost 3 yearsSeems the
winnat
service is started by windows hyper-v -
PDHide almost 3 years@MohammadHosseinGanjyar such a simple solution well done
-
Matt West almost 3 yearsI had no idea this package existed. Only 7:30am and my day is already made.
-
anderskristo over 2 yearsWow... this definitely saved my evening
-
hussamsindhu over 2 yearsyeah It's working thanks, but what package it installed ?
-
Voxlinou over 2 yearsThis does not fix the user's problem or help fixing it, please look on how to write a good answer
-
Eric Aya over 2 yearsThis is the same solution as in this other answer.
-
Admin over 2 yearsYour 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.
-
Matthew over 2 yearsThis worked for me too. Then I tried WiFi on and VPN off...also worked. Anyone know why this might be?
-
Droid Chris about 2 yearsyep this works great!
-
Shannon Cole about 2 yearsAwesome! Worked great. I love simple solutions.
-
TomDom about 2 yearsThanks a lot. This solved my problem. I've been trying to find a solution for the last couple of hours.
-
Gary about 2 yearsI am using
netstat -ano | find "14228"
and want to use this withtaskkill /PID xxx
. I am not able to pipe it with|
nor with>
. It is throwing up on me with a wrong format error. What am I missing? These are the two :netstat -ano | find "14228" | taskkill /PID xxx
ornetstat -ano | find "14228" > taskkill /PID xxx
. I have tried thisnetstat -ano | find "14228" | ( set /P var= && set var ) > taskkill /PID ........
-
Gary about 2 yearsI am using
netstat -ano | find "14228"
and want to use this withtaskkill /PID xxx
. I am not able to pipe it with|
nor with>
. It is throwing up on me with a wrong format error. What am I missing? These are the two :netstat -ano | find "14228" | taskkill /PID xxx
ornetstat -ano | find "14228" > taskkill /PID xxx
. I have tried thisnetstat -ano | find "14228" | ( set /P var= && set var ) > taskkill /PID ........
-
Towerss about 2 yearsAfter trying all the previous solutions I got here. There was no visible process running on port 3000. This solution worked for me. Thank you.
-
May'Habit almost 2 yearssorry, where is the setting put?