I built a Node.js web server on my computer, using the so-well-known-http-web-server-example of Node.js:
var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'content-type': 'text/plain'});
res.end('It works');
}).listen(3000, '127.0.0.1');
This works (as expected) on the computer that runs the server.
I would like to access the server from another computer, in the same LAN. Using ifconfig
on the terminal of the computer that runs the server (Apple MacOSX), I get: 192.168.0.6
.
So, in my other computer, I opened my browser and connected to http://192.168.0.6:3000
, but I get:
Oops! Google Chrome could not connect to 192.168.0.6:3000
My final aim, is to be able to connect to the server using my smartphone.
Any help would be welcome. Don't hesitate to ask for more details if necessary.
Thanks in advance :)
Given that the port is bind to any IP address other than 127.0. 0.1 (localhost), you can access it from any other system. To view your IP addresses, use ipconfig (Windows) or ifconfig (Linux) command. Find out the IP which is in the same network as the "other system" from which you want access.
Put the IP addresses of both of your computers' internet security antivirus network security as safe IP addresses if required. On your PC you type in: http://localhost/ inside your Firefox or Internet Eplorer browser to access your data on your webserver.
You can run node. js server on a typical shared hosting with Linux, Apache and PHP (LAMP).
127.0.0.1
is only local interface. Try to start listening all interfaces:
var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'content-type': 'text/plain'});
res.end('It works');
}).listen(3000, '0.0.0.0');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With