I was able to successfully access my node server through a local IP address (192.168.XX.XX) on my WiFi network with the following server code:
var express = require('express');
var app = express();
var server = require('http').createServer(app);
server.listen(8080, "0.0.0.0");
I went to 192.168.XX.XX:8080 and accessed the HTML file successfully.
Specifically, I'm using my phone to access the server but if I get off of the network and use cell service, I can't access the server. I looked up my external IP and got 76.XXX.XXX.XXX. When I go to 76.XXX.XXX.XXX:8080 from my phone (without changing any server code), I can't get to the server. I also tried switching to port 80 in the code and it still didn't work.
I have a McAfee firewall going and I tried to open 8080 to be externally accessible. I also turned the firewall completely off but still couldn't connect.
Any ideas?
The seemingly best solution is using Ngrok. It allows you to expose your local server to the internet. You can download and use it here: https://ngrok.com/
Related
I created an azure web app which send an http request:
axios.post('http://*mypublicip*:3000/write/' + Name, {
content: data[1]
})
meanwhile my computer has a running express server:
app.listen(3000, () => console.log(`Server running on port ${port}`));
all my functionality works when I use it locally by sending the request to localhost instead of my ip.
I also tried adding host '0.0.0.0' to my app.listen.
what am I missing? thanks
This problem has nothing to do with your webapp.
So I will not test the webapp program anymore, you can access your http request of http://*mypublicip*:3000/write/' + Name through other machines (not PCs in the LAN) , My test environment is vm built in azure. You will find that your request cannot be accessed successfully.
The reason is that the ip you found in ipconfig in cmd should not be your host ip, but the Internet ip assigned to you by the operator. This ip is used by many hosts. Simply put, this ip is not just one of yours Machines.
So cause your problem to happen. It is recommended to use intranet penetration tools to achieve this. It means to use the intranet penetration tool to expose your 3000 port.
To solve your problem, I used ngrok.
Build the project locally and monitor port 3000.
Local visit, check the effect.
Access in the virtual machine, discovery failed.
After installing ngrok, the virtual machine accesses the new address and it succeeds.
First allow port 3000 to be exposed.
Test in vm, it works.
I'm currently having an issue when trying to port forward my modem to my Node.js server. Sorry if this is a duplicate question, i've spent some time looking at familiar topics.
I'm using the express framework, I've included a small snippet, so you can see what port the node.js server is listening too.
(Quick Question: Do I use server.listen or app.listen in this situation? What's the difference?)
var express = require('express');
var app = express();
var server = require('http').Server(app);
app.listen(4000);
I've also attatched a picture containing:
The node.js server running.
ipconfig (so you can see my local IP address)
and a screenshot of my modems' port forward settings.
When I google "Whats my IP Address" and retrieve my public IP address, then navigate to it I receive an error on my browser stating that the server took to long to respond. I assume the server isn't being port forwarded, however I can't seem to isolate the issue.
Any help would be greatly appreciated?
Your modem/wifi router's public IP address keeps changing frequently every now and then or when your router reboots. This is because of DHCP.
Port forwarding and hacking your wifi router firewall rules to allow public access to your home or office network is an unsafe practice.
That's where simple tools like SocketXP come in handy. SocketXP will provide you a public URL to access your NodeJS server running in your localhost machine like your home/office laptop or server.
Here is a great blog article on how to install and setup SocketXP to access your local NodeJS server from the internet.
If you're wrapping your Express app in a http server, you should listen on it like so server.listen(4000).
Also make sure that your firewall on your computer is not blocking access to that port. A good alternative to the port forwarding + disabling firewall rules is to use a reverse proxy, something like ngrok for example
I have a Node.js program running on Mac and Windows, both allowing visitors over the internet. My set up is super simple:
var http = require('http');
var s = http.createServer();
s.listen(80, process.argv[2] || '127.0.0.1');
And when I run the server I will use node server.js 0.0.0.0 to trigger process.argv[2] so it doesn't just listen on the request from the local server.
Yet when I move the same server application to Ubuntu, it stops working. For example, if the Ubuntu server has an IP address of 172.18.x.x, it will only response to requests from machines in the same network, having IP address of 172.18.x.x. If a device has an IP address of 172.19.x.x, it doesn't response. It also doesn't response to forwarded internet calls if the forwarded request didn't come from a routing machine that has an IP address of 172.18.x.x!
This likely has nothing to do with Node.js. It is probably your Ubuntu system that is blocking the connection. Specifically, some firewall or security package installed as a dependency by one of your apps, or otherwise.
hey guys i made chat for my chat application on my local host with some guids i found on the internet and im struggling to add is to my real server on line, now it listening to port localhost:3000 but i dont know what sould i do for a real server, help me please!
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
server.listen(process.env.PORT || 3000);
app.get('/',function(req,res){
res.sendFile(__dirname + '/index.html');
});
Now you're gonna need to set up your server. I recommend digitalocean for a cheap cloud VPS. You can follow this tutorial.
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
Basically you'll need to set up a process manager. For node i recommend PS2.
If you're looking to host your chat server from your residence, you will need to route external node traffic to the machine (or VM) which runs your node server.
You can do this by port forwarding. That means you'll need to go into your router's UI/settings panel and create a new port forwarding rule. Namely, you will probably want external traffic which arrives on port 80 to route to the local IP of your node server's machine on port 3000.
Once this is done and the changes have been saved to your router config, you should already be able to put your public IP in a browser's URL bar and be directed to your web-facing node app.
Beyond the scope of this question is getting yourself a domain name, and attaching it to your public IP, either statically or dynamically depending on your needs. That way, you wouldn't have to enter your public IP in the URL bar, you would just have to enter your domain, i.e. myfirstchatapp.com
So I have the following URL that leads external users to my port-forwarded XAMPP website.
http://ip_to_my_computer:433
However, my node server is on port 466. How do I connect to it? I can't do
var client = io.connect('http://ip_to_my_computer:433:466');
Thanks!
It looks to me like you're trying to initiate a client request from your XAMPP hosted server (like a .php or .js script) to your Node.js instance?
Simply:
var client = io.connect('http://ip_to_my_computer:node_server_port');
And in your case, you claim your Node server is running on port 466.
I'd bet though that your OS will block a port that low - try changing your Node server to listen on a port between 8000 - 9000.