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

前端 未结 30 2069
闹比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 18:12

    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.

    0 讨论(0)
  • 2020-11-28 18:13

    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

    3. End this particular task.

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

    0 讨论(0)
  • 2020-11-28 18:14

    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

    0 讨论(0)
  • 2020-11-28 18:15

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

    0 讨论(0)
  • 2020-11-28 18:15

    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!!

    0 讨论(0)
  • 2020-11-28 18:15

    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)

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