why node js socket not working when change port to

2019-08-30 06:18发布

问题:

Normally in app.js i use this code on port 3000 it's work good (on my-domain.com:3000).

.

http.listen(3000, function(){
    console.log('start server on port :3000');
});

then i want to use on https, so i change app.js to

http.listen(443, function(){
    console.log('start server on port :443');
});

When run node app.js , it's show error

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::443
    at Object.exports._errnoException (util.js:1012:11)
    at exports._exceptionWithHostPort (util.js:1035:20)
    at Server._listen2 (net.js:1252:14)
    at listen (net.js:1288:10)
    at Server.listen (net.js:1384:5)
    at Object.<anonymous> (/home/admin/web/my-domain.com/public_html/app.js:28:6)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)

Normally i have to access to my-domain.com:3000 for user chat. So i want to know how can i access to https://www.my-domain.com for user chat ?

回答1:

You have the following error message:

Error: listen EADDRINUSE :::443
[...]

This message means that the port 443 is currently in use by some process.

You can check which process is actually using the said port by executing one of the many tools for network checking (such as netstat for Windows, lsof or netstat on Linux).

Refer to the manual for those tools to achieve the correct result, based upon your operating system.