0

I have a js file with the following code

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

Now, if I access the server by 127.0.0.1:3000 its perfectly fine, but I want to access it from my own computer ip address. I write 192.xxx.x.xxx:3000, but I cant access it. Since I am developing an android application I need the ip address of the computer in order to run it, can someone explain why I am unable to access it?

3

1 Answer 1

4

When you say listen(3000, '127.0.0.1'), you're explicitly binding your server to port 3000 on IP 127.0.0.1.

You probably just want to bind to all IPs, which you can do by omitting the bind host:

listen(3000);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.