node.js express socket.io port 3000 in use

后端 未结 8 438
南笙
南笙 2021-02-02 16:33

I\'ve been following this(http://socket.io/get-started/chat/) tutorial on how to make a simple chat application using socket.io.

I tried to however use Express to create

相关标签:
8条回答
  • 2021-02-02 17:03

    I ran into this problem too and I solved it by this:

    Do not use npm start to start your web app

    Use node app.js instead

    0 讨论(0)
  • 2021-02-02 17:06

    I resolved the same problem with an express app doing this:

    1. Edit the file "yourap/bin/www"
    2. find the line :

      var port = normalizePort(process.env.PORT || '3000');

    3. replace it by:

      var port = normalizePort('XXXX');

    where XXXX is the port number you want to use

    Then youre free to do npm start! xD

    0 讨论(0)
  • 2021-02-02 17:06

    I solved it by this:

    npm install shelljs

    and add code for kill nodejs process before start listen port

    var shell = require('shelljs');
    shell.exec("pkill nodejs");
    shell.exec("pkill node");
    
    /* Make the http server listen on port 3000. */
    http.listen(3000, function(){
     console.log('listening on *:3000');
    });
    
    0 讨论(0)
  • 2021-02-02 17:13

    One of the best way to do this during the development would be through IDE where you can do comprehensive debugging and step through the code.

    If you are using WebStorm, this works. From run configurations -> Edit Configurations -> Nods.js and add the app.js as the node parameter. See below arrow in the screenshots for more details.

    0 讨论(0)
  • 2021-02-02 17:13

    for me helps to make use 3000 || 3333, and it's fix the issue

    0 讨论(0)
  • 2021-02-02 17:15

    I had (forgotten that I had) previously installed ntop, which by default also uses port 3000, and was therefore getting the same error as described here.

    As others have mentioned, use netstat or lsof to find the offending service (and prefix the command with sudo, to get the correct process name):

    sudo lsof -P | grep ':3000'
    

    - or -

    sudo netstat -anp tcp | grep 3000
    

    On Ubuntu, the service is disabled with (simply):

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