Changing Node.js listening port

后端 未结 3 719
名媛妹妹
名媛妹妹 2020-12-06 04:34

I just installed node.js on Windows. I have this simple code which does not run:

I get: Error: listen EADDRINUSE

Is there a config file that

3条回答
  •  天涯浪人
    2020-12-06 04:56

    There is no config file unless you create one yourself. However, the port is a parameter of the listen() function. For example, to listen on port 8124:

    var http = require('http');
    http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
    }).listen(8124, "127.0.0.1");
    console.log('Server running at http://127.0.0.1:8124/');
    

    If you're having problems finding a port that's open, you can go to the command line and type:

    netstat -ano
    

    To see a list of all ports in use per adapter.

提交回复
热议问题