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

前端 未结 30 2067
闹比i
闹比i 2020-11-28 17:24

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 loc

相关标签:
30条回答
  • 2020-11-28 17:50

    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

    0 讨论(0)
  • 2020-11-28 17:50

    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
    
    0 讨论(0)
  • 2020-11-28 17:50

    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 =)

    0 讨论(0)
  • 2020-11-28 17:50

    Kills all the running ports (mac):

    killall node
    
    0 讨论(0)
  • 2020-11-28 17:51

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

    0 讨论(0)
  • 2020-11-28 17:52

    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.

    0 讨论(0)
提交回复
热议问题