why node js socket not working when change port to https? - node.js

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 ?

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.

Related

Running simple node js server

I am running a simple node js server on my Mac. I also have mamp installed. Just FYI.I am able to go to localhost:8888 just fine and preview the web page. However, in my server.js file, if I include the host as a parameter to the server.listen function like so
server.listen(127.0.0.1, 8888, function(){
console.log('Server running');
})
I get the following error in my terminal.
Error: listen EADDRINUSE 127.0.0.1
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at Server.setupListenHandle [as _listen2] (net.js:1338:19)
at listenInCluster (net.js:1396:12)
at Server.listen (net.js:1491:5)
at Object.<anonymous> (/Users/username/Desktop/nodeServer/server.js:12:8)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
Users-Mac-Pro:nodeServer user$
If I just have
server.listen(8888, function(){
console.log('Server running');
})
everything works fine. Does this have anything to do with the fact that I have mamp installed? Just want to understand why one works and the other doesn't.
Try putting your host after port as following
server.listen(8888, '127.0.0.1', function() {
console.log('Server running');
})
app.listen documentation
app.listen([port[, host[, backlog]]][, callback])
Some other process might have been using 8888 port. You can either kill that process or use someother port for your nodejs server.
To get the process id of the process using port 8888, use
lsof -i tcp:8888
and kill the process using
kill -9 <pid>
Hope this helps.
Probably you're currently running your server in that port. Try with:
killall node

Hot can i use node js socket io on port 443 as same as https?

Hot can i use node js socket io on port 443 as same as https ?
When i use this command line ss -nltp|grep :443 for check application that currnetly working on port 443, i get this
LISTEN 0 128 xxx.xx.x.xxx:443 *:* users:(("nginx",pid=27314,fd=10),("nginx",pid=27313,fd=10),("nginx",pid=27312,fd=10))
So in app.js i change to this
http.listen(443, function(){
console.log('start server on port :443');
});
for use node js socket io on https port
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)
I want to know how can i use multiple application on the same port, in this case on poer 443 ?
Normally i have to access to my-domain.com:3000 for use node js socket io. So i want to know how can i access to https://www.my-domain.com for use node js socket io ?

Error while running application through NPM node and ember

I am new to this whole npm node concept and currently on learning phase. I am trying to resolve an error that is not letting me perform the Event router for my web application in node. Here is the error below and do let me know what is the problem or issue and what steps to take to resolve it.
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!
Debugger listening on port 15454
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8080
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at Server.listen (net.js:1382:5)
at EventEmitter.listen (/home/ubuntu/workspace/nodeproject/node_modules/express/lib/application.js:617:24)
at Object.<anonymous> (/home/ubuntu/workspace/nodeproject/app.js:55:5)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
Error: listen EADDRINUSE :::8080
Some other process is already listening on port 8080. Either stop that process or change the port of the ember app.

New to using NodeJS Express Server

I trying to view a static html page at localhost, but get the following error message:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EACCES
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1020:19)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
at Function.app.listen (/home/phil/xProgramming/AngJS/Project/node_modules/express/lib/application.js:536:24)
at Object.<anonymous> (/home/phil/xProgramming/AngJS/Project/server.js:6:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I've tried killall, but I still get the same error message.
I new to Linux and am using Ubuntu 14.04
The EACCES error normally means that you are trying to bind to a port and failing. This is probably because you are trying to bind to port 80 without root permissions. Try running node with root permissions and it should work.
sudo node server.js
or
sudo nodejs server.js
Depending on how you have Ubuntu setup.
If this is a development environment instead of running as root you should use a port greater than 1024. Typically you will find people using port 3000 for node though 8000 and 8080 are also used. Here is how I normally do this when using Express.
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("Listening on " + port);
});

tutorial of node.js code sample fails with Error: listen EADDRINUSE

I am a beginner programmer that is trying to learn node.js using the following tutorial site
http://www.nodebeginner.org/#hello-world
I got to the point where I was trying to set up the server but got an error with the below code
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:884:11)
at Server._listen2 (net.js:1022:14)
at listen (net.js:1044:10)
at Server.listen (net.js:1110:5)
at Object.<anonymous> (/Users/.........../server.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
any help would be appreciated
EADDRINUSE means that address is in use.
Basically, you tried to start two servers at the same time that both use port 8888. You have to stop or kill one before starting another. The other server on port 8888 could be another process running your node script, or it could be something else in the system that serves content on port 8888.
Alternatively, you can get this if you don't let the socket settle for a few seconds after terminating the old server.
A more practical answer based on this great one.
Find out what is using port 8888 with this command:
lsof -i tcp:8888
You should get something like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 86456 myName 13u IPv6 0xa6b50fb47c9c3c81 0t0 TCP *:ddi-tcp-1 (LISTEN)
Now that you know which process is in the way, KILL IT! Softly, like so:
kill -15 86456

Resources