Node.js Port 3000 already in use but it actually isn't?
Asked Answered
L

46

398

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.

Legofmutton answered 4/9, 2016 at 22:38 Comment(15)
There 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 systemMutant
Have you tried browsing to localhost:3000 ?Ridinger
@Mutant I have checked Resource Monitor on Windows 10 and there is no process listening on port 3000. Unless its one that I cannot see?Legofmutton
have you tried #48698Propagandize
@Ridinger 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 runningLegofmutton
The 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.Ridinger
And of course, this might work..Ridinger
@Ridinger I tried TCPView and netstat and there is nothing running on port 3000, I also tried restarting my laptop and still the same issue.Legofmutton
I 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?Ridinger
@Ridinger 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"Legofmutton
Possible duplicate of Node / Express: EADDRINUSE, Address already in use - Kill serverZebulen
Marked as dupe, try: ps aux | grep node then kill -9 PIDZebulen
My 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.Corncob
Sounds 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?Onagraceous
For me it was my .env - so make sure there are no syntax errors there.Hesler
A
771

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

Agnosticism answered 16/7, 2017 at 15:29 Comment(12)
I'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.Manizales
tskill didn't working for me on windows. taskkill /F /PID myPIDhere - this workingAntonyantonym
I get nothing with only lsof but with sudo lsof I get something, and killing that process solved this problem.Greaves
Is 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.Sands
taskkill did not work for me on git-bash, but tskill did. thanks.Stun
worked for me just had to add the PID displayed from the "lsof -i tcp:3000" commandEnisle
Would have even better if you had explained the commands in detail too but stackoverflow is life saving.Capote
I killed the process, but another one immediately started with a different PID, also using port 3000Psalm
I am using netstat -ano | find "14228" and want to use this with taskkill /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 or netstat -ano | find "14228" > taskkill /PID xxx. I have tried this netstat -ano | find "14228" | ( set /P var= && set var ) > taskkill /PID ........Tricornered
Who is having trouble still: 1) use "sudo lsof -i tcp:3000" instead of the first command suggested 2) instead of PID, you have to had a number that usually is 290, but you have to insert the one you looking to close!Ralph
If anyone still having issues on Windows, it might be a silent "listen EACCES: permission denied" issue. Try net stop winnat, then net start winnat. Credit to this post.Esmeralda
lsof -t -i tcp:3000 | xargs kill -> this works for me on macOSDing
J
518

You can use the following command as a reference to terminate a process running on a specific port:

npx kill-port 3000

enter image description here


To terminate processes on multiple ports, you can use the following command:

npx kill-port 3000 8080 4200
Jubilee answered 22/4, 2020 at 10:27 Comment(1)
I had no idea this package existed. Only 7:30am and my day is already made.Uel
E
65

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
Extramural answered 19/1, 2018 at 5:33 Comment(4)
Neither 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.Stateroom
thanks for the killall -9 node command. it worked on goorm IDETermitarium
killall -9 node it worked. Thanks!Helmand
thanks, in my case kill -9 <PID> is not working but sudo kill <PID> works for me!Oswaldooswalt
I
36

Killing a process that owns port 3000

First, let’s take a look at how we can kill a process that has a port open.

Using the lsof command, we can retrieve the PID that has the given port:

$ lsof -i :3000 -t
12345

Then we can kill this process just by doing:

$ kill 12345

Let’s turn this into a one-liner:

lsof -i 3000 -t | xargs kill

If you’re using an environment variable to set the server port, we can specify that instead of hardcoding our values:

lsof -i ${PORT} -t | xargs kill

Lastly, we can default to port 3000 if the environment variable isn’t set:

lsof -i ${PORT:-3000} -t | xargs kill

Getting nodemon to execute hooks

Nodemon lets you set up event hooks through nodemon.json configuration file:

{
  "events": {
    "crash": "sh -c 'lsof -i :${PORT:-3000} -t | xargs kill'"
  }
}

This will cause nodemon to execute sh -c 'lsof -i :${PORT:-3000} -t | xargs kill command whenever your app crashes, thereby killing the child process it spawned that’s keeping the port open.

or you can try this one

fuser -k PORT-NO/tcp

Eg:

fuser -k 3000/tcp

You can try this aswell

fuser -n tcp -k PORT-NO

Eg:

fuser -n tcp -k 3000

ON MAC

kill -9 $(lsof -ti:PORT_NO)

Eg:

kill -9 $(lsof -ti:9229)
Impious answered 8/12, 2019 at 10:12 Comment(3)
This 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!Intertexture
Im experiencing this issue although no processes are returning from lsof -i :3000 -t =\Kp
@Kp try this one fuser -k port-number/tcpImpious
Q
36

I also encountered the same issue. The best way to resolve is (for windows):

  1. Go to the Task Manager.

  2. Scroll and find a task process named. Node.js: Server-side JavaScript Image added for reference

  3. End this particular task.

There you go! Now do npm start and it will work as before!

Qualitative answered 12/7, 2020 at 5:44 Comment(0)
M
34

I had the same problem. (The below steps work fine on Windows 10):

  1. Open Task manager (press Ctrl+Alt+Delete)
  2. Select the 'Processes tab'
  3. Search for 'Node.js: Server-side JavaScript'
  4. Select it and click on 'End task' button

Now you can run npm start.

Hope it helps you.

Melaniemelanin answered 27/6, 2018 at 19:9 Comment(0)
A
27

For windows, The Task Manager would definitely show a node process running. Try to kill the process, it will solve the problem.

Aliaalias answered 17/7, 2017 at 14:5 Comment(0)
P
20
 killall -9 node

the above command can exit vs code ssh connection when you are developing remotely and kill all node processes that can lead to problems especially if you have some apps on production using node , there is a better way to do it by 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 -9 PID

or

   kill -HUP PID 
Panta answered 23/4, 2021 at 5:21 Comment(2)
I 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 portFurthermore
its come with a new port auto restart did u know why ?Roxanneroxburgh
T
14

I was using express server with nodemon on NodeJS. I got the following message and it seems an error:

$ node ./bin/www
Port 3000 is already in use

There is a general solution that if you terminate all node server connections, you can add this code in your package.json file:

"scripts": {
    "start": "node ./bin/www",
    "stop": "taskkill -f -im node.exe"
},

In addition, I've found several solutions windows command and bash on Win 10 x64.

All my notes are here:


# Terminate all NodeJS Server Connections

$ taskkill -f -im node.exe
SUCCESS: The process "node.exe" with PID 14380 has been terminated.
SUCCESS: The process "node.exe" with PID 18364 has been terminated.
SUCCESS: The process "node.exe" with PID 18656 has been terminated.

# Example: Open the Windows Task Manager and see "node.exe" PID number on Windows

>> Command Line
$ netstat /?
$ netstat -a -n -o
$ netstat -ano

# Kill a process in Windows by Port Number (Example)

For Help:

$ taskkill /?
$ tskill /?

Code 1:

$ taskkill -pid 14228
ERROR: The process with PID 14228 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).

Code 2:

$ taskkill -f -pid 14228
SUCCESS: The process with PID 14228 has been terminated.

Code 3:

$ tskill 14228

# Command line for looking at specific port

in cmd:

$ netstat -ano | find "14228"

in bash:

$ netstat -ano | grep "14228" or $ netstat -ano | grep 14228

# Find node.exe using "tasklist" command

in cmd:

$ tasklist | find "node"

in bash:

$ tasklist | grep node
$ tasklist | grep node.exe
node.exe                     14228 Console                    2     48,156 K
node.exe                     15236 Console                    2     24,776 K
node.exe                     19364 Console                    2     24,428 K
Trocki answered 20/1, 2020 at 5:30 Comment(2)
You 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.Araarab
I am using netstat -ano | find "14228" and want to use this with taskkill /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 or netstat -ano | find "14228" > taskkill /PID xxx. I have tried this netstat -ano | find "14228" | ( set /P var= && set var ) > taskkill /PID ........Tricornered
D
13

I was facing the same issue today since I found the solution.

The issue is because there were node services is running in the background even if nodemon restarts.

I've gone through many answers but all come with multiple commands. There is the simple command I found for my case

sudo pkill node

This will terminate all the running processes from the node and your nodemon will start working as expected.

Dibucaine answered 14/9, 2021 at 17:53 Comment(0)
I
11

I've seen the same thing and tried all the suggestions above without success. Here are steps that resolve it for me: - turn off wifi - npm start (this should work) - turn on wifi

I'm not exactly sure what the root issue is but that resolved it for me.

Infringe answered 16/7, 2018 at 18:19 Comment(4)
I just had this happen to me as well. netstat -ano didn't list anything using port 3000.Airel
Holy 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 :)Murcia
for 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.Bullhead
This worked for me too. Then I tried WiFi on and VPN off...also worked. Anyone know why this might be?Jeremiad
T
9

This is an old question, but none of the responders seem to have actually read it. I had the same problem and the issue was that Windows sometimes reserves blocks of ports and stops you from using them. The port does not show up via netstat or any other tool. You can read about it here:

Essentially you can tell Windows to leave your port alone with this:

netsh int ipv4 add excludedportrange tcp startport=3000 numberofports=1 store=persistent
Tachistoscope answered 8/9, 2021 at 9:29 Comment(4)
Thanks a lot. This solved my problem. I've been trying to find a solution for the last couple of hours.Majolica
After trying all the previous solutions I got here. There was no visible process running on port 3000. This solution worked for me. Thank you.Cayuse
Thanks! This worked after combining it with this command: net stop winnatTl
This should be higher on the list! Might also have to net stop winnatAngy
L
8

enter image description here

Open your command prompt and first run this command:

netstat -ano | findstr :7001

And then run this command:

taskkill /PID 2820 /F
Lynd answered 10/1, 2022 at 12:5 Comment(0)
L
6

It happens when no task is listed with a command

lsof -i:3000

And still, you get an error

Error: listen EADDRINUSE: address already in use 0.0.0.0:3000

One reason is that in Nginx conf.d check none of configuration is listening on port 3000

Liesa answered 12/11, 2021 at 17:14 Comment(1)
This does not fix the user's problem or help fixing it, please look on how to write a good answerRife
M
5

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. You can stop process with ctrl+C in the terminal window.

Or, perhaps you are listening to the port multiple times due to copy/pasta =)

Mcmullan answered 4/9, 2016 at 22:51 Comment(7)
Thanks for the help! I don't have any other terminal windows open, anything else I should check?Legofmutton
find 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 8080Mcmullan
I 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?Legofmutton
@Legofmutton 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?Mcmullan
Thank 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!Legofmutton
Here'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 the GET 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.Redhanded
[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.Redhanded
L
5

Open Task Manager (press Ctrl+Alt+Del Select the 'Processes Tab' Search for 'Node.js: Server-side JavaScript' Select it and click on 'End task' button

Leucas answered 6/5, 2019 at 22:1 Comment(0)
C
5

I have encounter a weird port problem on win10 recently, can not start server process listen on port 8080, and I changed it to 18080 , then it works, but after a while, same problem appear again. But I can not find any process use the port, I have tried currpots and netstat , none of them work, and I try open port by

python -m http.server 18080
python -m http.server 18081
python -m http.server 18082
python -m http.server 18083
python -m http.server 18084
...

, Most shows similar message "port already in use" Fortunately, I searched and found out why. By

netsh interface ipv4 show excludedportrange protocol=tcp

Can see some port are exclude for use, through these port not opened and listened. And by

net stop winnat

Most excluded port are released, these port can be used then.

Cowardly answered 14/6, 2021 at 2:21 Comment(2)
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.Ninth
Seems the winnat service is started by windows hyper-vCowardly
S
4

Came from Google here with a solution for High Sierra.

Something changed in the networking setup of macos and some apps (including ping) cannot resolve localhost.

Editing /etc/hosts seems like a fix:

cmd: sudo nano /etc/hosts/ content 127.0.0.1 localhost

Or simply (if you're sure your /etc/hosts is empty) sudo echo '127.0.0.1 localhost' > /etc/hosts

Stertorous answered 27/3, 2018 at 19:15 Comment(0)
F
4

I have spent 2h on finding out why EADDRINUSE wasn't allowing me to sart an app (other node-express servers were ok)... it started working after adding lazyConnect: true, to datasource configuration.

Don't ask me why it helped. I do not know. I am putting this info here just for people having the same issue.

Fond answered 24/9, 2018 at 20:57 Comment(2)
upvoted for the willingness to help AND a solution that may help find the root cause.Brenza
sorry, where is the setting put?Scriber
F
4

If you want to close only one port, just run this command. kill -9 $(lsof -t -i:3000)

The difference between pkill and kill is someone process clay. In kill you apply a filter. you just stop the port you want.

The pkill command closes all node processes. pkill -9 node

Use pkill to avoid memory leaks that occur occasionally during development. if there is more than one node, it kills them all.

The use of scripts in package.json is also exemplified.

"scripts": {
    "server:start": "cd server && yarn start",
    "server:restart": "cd server && yarn restart",
    "frontend:start": "cd frontend && yarn start",
    "frontend:restart": "kill -9 $(lsof -t -i:4200) && yarn start:frontend"
},
"scripts": {
    "start": "nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts",
    "restart": "pkill -9 node && start",
    "kill": "pkill -9 node"
},
Fletcherfletcherism answered 28/11, 2019 at 10:7 Comment(0)
C
3

I got this problem using Git Bash on Windows. I run npm start, or node app.js. After terminating it with Ctrl+C shortly and trying to start the server again using npm start or node app.js then I get this error message.

When I do this with the regular Windows Command Prompt, however, it works fine.

Or You can do it in another way. Open the Task Manager and Find the "Node.js:Server-side JavaScript" row. Select that and end task. It should work now.

Thanks.

Camarilla answered 16/2, 2019 at 9:33 Comment(0)
C
3
npx kill-port 3000 

then you can show like this:

Need to install the following packages:
[email protected]
Ok to proceed? (y)

then type : y

Conflation answered 28/10, 2023 at 16:54 Comment(0)
L
2

For windows users, you can use CurrPorts tool to kill ports under usage easily

enter image description here

Loadstar answered 3/10, 2018 at 11:46 Comment(0)
E
2

For windows user, Just simple stop all processes of Node.js in Task Manager

Hope it will help

Epithalamium answered 23/7, 2019 at 8:33 Comment(0)
P
2

if you called app.listen function many time on same port, you can get this error.

You can check your codes for any loop

Plinth answered 19/12, 2021 at 15:40 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.Cespitose
S
2

Just wanted to mention one issue that is not covered by the answers already given. It is related to Hyper-V (and Docker) "stealing" the port:

Quote from Docker issue (linked below):

Disable hyper-v (which will required a couple of restarts)

dism.exe /Online /Disable-Feature:Microsoft-Hyper-V

When you finish all the required restarts, reserve the port you want so hyper-v doesn't reserve it back

netsh int ipv4 add excludedportrange protocol=tcp startport=3000 numberofports=1

Re-Enable hyper-V (which will require a couple of restart)

dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All

https://github.com/docker/for-win/issues/3171#issuecomment-459205576

Smyth answered 3/8, 2022 at 17:4 Comment(0)
H
1

Try opening the localhost in your browser. Just type: localhost:3000 in the address bar.

If the app opens-up, it means your previous npm run is still active. Now, you can just make changes to the code and see the effects if you are designing the same app, or if you wanna run another app, just tweak the code (in index.js of previously running app) a little-bit and (probably refresh the browser tab) to make it crash ;)..... Now go run npm run start again from your new app directory. Hope this helps! :)

or

You can open the Task Manager (WINDOWS_KEY+X > Task Manager) and you'll see the "Node.js:Server-side JavaScript" row. Select that and end task....It should work now!!



If not, change the .env file of your app to include port:3002 and run the new app. This will allow you to run two separate apps on different ports. Cheers!!

Homophone answered 5/12, 2018 at 7:55 Comment(0)
I
1

Simple in linux

  • Open your terminal
  • Free port from processes -> kill $(lsof -t -i:$port)
Izaguirre answered 14/11, 2019 at 12:51 Comment(0)
P
1

Before running nodemon, Please start mongod first. You will never get this error.

Pintsize answered 26/5, 2020 at 10:8 Comment(0)
T
1

Late reply but it might help somebody:

In my case nothing was using port 3000 (same as OP, but all the answers are about killing the process that's using that port - which doesn't help).

However, in task manager, two copies of node.exe we running and would restart even if I killed them. If you right click on node.exe in taskmanager you'll see where those process are running. For me it turned out that Adobe Creative Cloud packaged it's own node.exe and that was causing me problems. Renaming the files (since I wasn't using the cloud service) worked for me.

Tachistoscope answered 25/5, 2021 at 9:11 Comment(0)
B
0

It may be an admin process running in the background and netstat doesn't show this.
Use tasklist | grep node to find the PID of this admin process and then kill PID

Bonney answered 10/10, 2018 at 13:33 Comment(0)
H
0

if you are using webstorm just make sure your default port is not 3000 from file -> settings -> Build, Execution, Deployment -> Debugger And there change

Built-in server port

and set it to "63342" or see this answer Change WebStorm LiveEdit Port (63342)

Hohenzollern answered 1/12, 2018 at 17:35 Comment(0)
O
0

In package.json scripts inlcude:

"start": "nodemon app.js --delay 1500ms"

I believe the issue was for me the time that the old port was not shutting down in time by nodemon for the restart. I experienced the issue using multer.

Oxytocic answered 8/7, 2019 at 7:9 Comment(1)
Adjust the delay as required.Oxytocic
T
0

server or app listen() methods might be added at 2 places. Search for listen() methods in the for the application startups thats why its returning as Server started at Port XXXX and Port XXXX already in use message coming side by side

Teens answered 9/10, 2019 at 5:53 Comment(0)
P
0

In my circumstance I had just started using VS Code and had followed a tutorial using Sequelize. In the end I had a bin/www file that had the listen() in there. I didn't know about this and I was running my app by running node app.js, when it didn't work I then added in the express server stuff with .listen() (which worked fine).

But when starting to use nodemon and VSCode it was pointed at bin/www and that required my app.js.

Long story short I had added .listen() to my app.js and was running app.js directly when I should have not added that and run bin/www.

Pohl answered 31/1, 2020 at 22:56 Comment(0)
K
0

In ubuntu first grab the process by using port number: sudo lsof -i:3000 then use kill command to kill the process, for example if the process PID is 4493 the use command: kill 4493 , for mac or windows find the related command

enter image description here

Kevenkeverian answered 19/4, 2020 at 13:48 Comment(0)
J
0

I have solved this problem because the MongoDB or there is another app u had run it before on this port, so to solve it kill the process from task manager, or just change the number of the port from 3000 to any other one.

Jamisonjammal answered 26/7, 2020 at 8:14 Comment(0)
D
0

It's very simple. You can fix it in 2 easy steps.

  1. Check your environment variables if there is a key/entry with name "PORT".
  2. If found delete that entry or rename it to something else.

It turns out that some other program is using that variable. Usually when you start react-scripts it will look for an environment variable with that title PORT.

Delhi answered 10/8, 2020 at 6:41 Comment(0)
B
0

This started happening to me today on Windows. I have restarted my computer and checked that nothing is on the port 3000 and it isn't.

I tried using 3001, 3005 with the same result.

In the end I moved to 8881 and it works now.

The only thing that changed for me was installing windows updates and updating source-map-explorer. As this also occurs in other apps its either something with Web Storm or windows. My guess is the ports may be locked down but the ones in the 88XX range are not.

Beasley answered 14/12, 2020 at 3:1 Comment(0)
J
0

You can use kill-port. Firstly, kill exist port and in second create server and listen.

const kill = require('kill-port')

kill(port, 'tcp')
    .then((d) => {
        /**
     * Create HTTP server.
     */
        server = http.createServer(app);

        server.listen(port, () => {
            console.log(`api running on port:${port}`);
        });
    })
    .catch((e) => {
        console.error(e);
    }) 
Jaimiejain answered 15/12, 2020 at 7:38 Comment(6)
What does kill-port do? How does it work?Mcmahan
@Mcmahan It kill its port that you want run for appJaimiejain
No, it doesn't. A port cannot be killed.Mcmahan
@Mcmahan you should read its document, please.Jaimiejain
Please put the relevant parts in your answer as well.Mcmahan
@MohammadHosseinGanjyar such a simple solution well doneDaytoday
R
0

I did everything here and nothing worked. No processes showed up when I checked the port. What eventually worked was turning of NoMachine. I'm leaving this here on the off chance it helps.

Rena answered 13/6, 2021 at 7:48 Comment(0)
V
0

In my environment within a linux docker container the lsof does not work.

I use netstat method instead:

 netstat -anpe | grep 5000 | grep "LISTEN"

this will output, 843851 is the pid:

tcp6     43      0 :::5000     :::*    LISTEN      1000       27888858   843851/node         

Then finallly :

kill -o 843851
Valene answered 9/7, 2023 at 7:39 Comment(0)
M
-1

It happend to me today after I interrupted the process and change the node version. To fix that I just restarted my computer, since no PID was shown using the port.

Malpractice answered 14/7, 2022 at 13:21 Comment(0)
S
-2

check for any process running on the same port by entering the command:

sudo ps -ef

You can find the process running on the respective node port, then kill the node by

kill -9 <node id>

If the problem still remains then just kill all the node

killall node
Schild answered 6/8, 2019 at 5:26 Comment(0)
N
-3

Kills all the running ports (mac):

killall node
Neocolonialism answered 19/4, 2019 at 1:27 Comment(0)
C
-3

Ensure you have localhost configured in your hosts file

127.0.0.1       localhost

https://github.com/facebook/create-react-app/issues/2843

Copywriter answered 24/11, 2021 at 8:16 Comment(1)
This is the same solution as in this other answer.Temporary

© 2022 - 2024 — McMap. All rights reserved.