Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: Cannot access server from different device on the same network

Tags:

node.js

NOTE: There are some others who have had similar problems, but those were solved by fixing small tidbits in the code involving how the server was listening (in examples that I've seen they put '127.0.0.1' as an argument in http.createServer(...).listen(). However, I do not have the same issue.

When I try to connect to my node.js server from a different machine on the same LAN network, Chrome says that it cannot connect.

This is testtesttest.js

var http = require('http');

http.createServer(function(req,res) {
    res.writeHead(200,{'Content-Type': 'text/plain'});
    res.end('Working');
}).listen(3000);

When I try inputting 192.168.1.73:3000 (of course 192.168.1.73 is the ip of the machine that I'm running the server on) into the browser (Chrome, although I've tried other browsers as well and I have similar problems) of my other machine, it gives the error "Oops! Google Chrome could not connect to 192.168.1.73:3000". When I type the same address onto the local machine, it works fine.

I'm not exactly sure what to do. I honestly hope this is just a stupid mistake on my part (I'm sorry for possibly wasting your time) and not something that I have to go into my router for.

Thanks very much for any help.

like image 633
AbsoluteZero2A03 Avatar asked Mar 19 '13 06:03

AbsoluteZero2A03


People also ask

How many concurrent connections can node js handle?

To address these issues, Node. JS uses a single thread with an event-loop. In this way, Node can handle 1000s of concurrent connections without any of the traditional detriments associated with threads.

CAN node js handle high traffic?

Since Node. js uses non-blocking IO, the server can handle multiple requests without waiting for each one to complete, which means Node. js can handle a much higher volume of web traffic than other more traditional languages.


1 Answers

Try changing this

.listen(3000);

to this

.listen(3000, "0.0.0.0");
like image 57
user568109 Avatar answered Oct 22 '22 10:10

user568109