Node.js Port 3000 is already in use, but is it really not?

I have been working with the node.js project for several weeks and it works great. I usually use "npm start" to launch my application and view it in a browser on the local host, port 3000.

Today, I started getting the following error when starting npm:

Server started on port 3000 Port 3000 is already in use 

I checked the resource monitor and I do not have another process running on server 3000. Why should I get this error message?

In my app.js, I have the following code to set the port ... is this wrong? It worked perfectly, so I'm not sure what I'm 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 tried running netstat and TCPView to check which process uses the port but nothing is used with this port. I also tried restarting my laptop, but still getting the same error.

+56
source share
20 answers

You can search how to kill this process.

To search for Linux / Mac OS (sudo) run this is in the terminal:

 $ lsof -i tcp:3000 $ kill -9 PID 

On Windows:

 netstat -ano | findstr :3000 tskill typeyourPIDhere 

change tskill for taskkill to bastard bash

+146
source

This happens sometimes, as @sova suggested. It happens to me sometimes, EADDR is in use. Typically, in the background, a terminal window is hidden that still starts the application. And it is also with me.

It happens when you open the terminal for a long time, yes, you are right, you stopped the process. But sometimes it did not stop in the background. The best solution is that you close the terminal and run it again. He will solve your problem. because in my case it works.

Besides,

 sudo lsof -i:<PORT_NO> 

close the instance for the current time, but could not stop the process in the background. So, at a time

 sudo kill <PID> 

works, but again, when we update our code and save it, this problem arises again, as when using Nodemon .

Thus, exit from the terminal will solve the problem. OR

  killall -9 node 
+20
source

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

+16
source

I have the same problem. (The following steps work fine on Windows 10):

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

Now you can run npm start .

Hope this helps you.

+11
source

This happens to me sometimes, EADDR to use. Typically, in the background, a terminal window is hidden that still starts the application. You can stop the process with ctrl + C in the terminal window.

Or maybe you are listening on a port several times due to copy / pasta =)

+3
source

I saw the same thing and tried unsuccessfully all the sentences. Here are the steps that enable this for me: - disable wifi - npm start (this should work) - enable Wi-Fi

I am not quite sure what the root is, but that resolved this for me.

+3
source

Open the task manager (press Ctrl + Alt + Del. Select “Process Tab.” Find “Node.js: server-side JavaScript.” Select it and click on the “End Task” button.

+3
source

Came from Google here is a solution for High Sierra.

Something has changed in the macos network setup, and some applications (including ping) cannot resolve localhost.

Editing / etc / hosts looks like a fix:

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

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

+2
source

I spent 2 hours figuring out why EADDRINUSE does not allow me to send the application (other servers with the express lazyConnect: true, were fine) ... it started working after adding lazyConnect: true, to the configuration of lazyConnect: true,

Do not ask me why this helped. I dont know. I put this information here only for people having the same problem.

+1
source

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

When I do this with a regular Windows command line, it works fine.

Or you can do it differently. Open the task manager and find the line " Node.js: JavaScript on the server side ." Select this and complete the task . This should work now.

Thank you

+1
source

For Windows users, you can use the CurrPorts tool to easily kill ports

enter image description here

0
source

This may be an administration process running in the background, and netstat does not show this.
Use tasklist | grep node tasklist | grep node tasklist | grep node tasklist | grep node to find the PID of this administration process and then kill PID

0
source

if you use webstorm, just make sure that your default port is not 3000 from the file -> settings -> Build, execute, deploy -> Debugger. And there are changing

Embedded Server Port

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

0
source

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

If the application opens, it means that your previous npm run is still active. Now you can just make changes to the code and see the effects, if you are developing the same application, or if you want to run another application, just adjust the code (in index.js of the previously launched application) a little and (and) maybe refresh the tab browser) so that it works;) ..... Now run npm run start again from your new application directory. Hope this helps! :)

or

You can open the task manager (WINDOWS_KEY + X> Task Manager), and you will see the line "Node.js: Server-side JavaScript". Choose this and complete the task ... It should work now!



If not, modify your application's .env file to enable port:3002 and start a new application. This will allow you to run two separate applications on different ports. Hooray !!

0
source

The package.json scripts have:

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

I believe the problem was that the old port did not shut down in time using nodemon to restart. I ran into a problem using multer.

0
source

Server or listen () application methods can be added in 2 places. Searching for listen () methods to launch applications is why its return as a server started from port XXXX, and port XXXX already uses a message coming nearby

0
source

It works on Mac, did not try it on Windows: pass the port number you want to stop / kill, for example, port 8000:

 pkill -8000 node 
-one
source

For Windows users, just stop all Node.js processes in the task manager

Hope this helps

-one
source

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

 sudo ps -ef 

You can find the process running on the corresponding host port, and then kill the host with

 kill -9 <node id> 

If the problem still remains, just kill all the nodes

 killall node 
-one
source

For Mac users, force the process to complete using the activity monitoring application. Select npm from the process and press the X button to exit or force exit the process.

I ran into this problem when updating and restarting the code editor and fixed it using the activity monitor

npm in activity monitoring application

-2
source

All Articles