Reputation: 11
I'm experimenting with node.js and express.js.
When I try to connect to my web server from any computer in my network, it works, but then when I try to connect from outside network the connection times out.
var app = require('express')();
var http = require('http').Server(app);
app.get('/', function(req, res) {
res.send("Hello World");
});
http.listen(3000, '0.0.0.0', function() {
console.log("Listening on port 3000!");
});
Upvotes: 1
Views: 125
Reputation: 17430
I just tested your code and I'm able to access the server from outside my local network by navigating to:
So the code is correct. It could be that you need to open the port 3000
to the outside world. Here's how it can be accomplished.
Here's mine for example:
Where 192.168.1.130 is the local IP of the PC I'm running the http server on.
Don't forget to click the Save settings button in that interface to apply the changes.
Install ngrok through their website or without leaving the command prompt, with the ngrok node wrapper.
npm install ngrok -g
Start your http server and then run:
ngrok http 3000
Navigate to one of the url in front of Forwarding
:
The free version is more for a quick test and less as a definitive way to expose a service in a production environnement since every time you restart ngrok, a new user-hostile url is given to you.
Upvotes: 2