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

前端 未结 30 2070
闹比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:07

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

    Hope it will help

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

    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.

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

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

    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.

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

    Simple in linux

    • Open your terminal
    • Free port from processes -> kill $(lsof -t -i:$port)
    0 讨论(0)
  • 2020-11-28 18:10

    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

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