Access private http server - node.js

I built a Nodejs HTTP server. It's running on localhost:3000.
From outside the Local Area Network, how does one make a request to the private HTTP server? Messing with the router manually is not an option; process should be automated.
I've looked at various techniques - and I'm confused:
Mapping the localhost port to the external ip address (node-nat-pmp)
HTTP tunneling (node-tunnel)
SOCKS (shadowsocks-nodejs)
CONNECT method in request header
It seems that everything is built for a client tunneling out through a firewall, I want to tunnel a request in through the firewall and to a private server. Or just run the localhost port on the external ip.
Any help would be appreciated. Confused.

If you need to access an internal service from outside of your network, you typically have two options:
Configure Port Forwarding on your router - You mentioned this isn't a possibility
Use UPnP to ask your router to open a port for you - This is often disabled as it is a security risk, but if not, look into https://github.com/TooTallNate/node-nat-pmp

Related

Can't establish a connection NodeJS

I am a novice at networking, I have a NodeJS server running with server.listen(3000, '10.0.0.7'); and have forwarded port 3000 with the internal IP address of my server being 10.0.0.7. I can connect from another machine on my network by putting in the browser: 10.0.0.7:3000. It is my understanding that my external IP address should connect me to the router which should then forward me to the server I have set up on 3000.
Am I missing something important? Because I am unable to connect via the external IP address.
Also please note that my firewall is disabled.
I am neither a network expert so excuse me if I use any incorrect terms. In my understanding, you are right about the current configuration, however you are missing the last step. By default, your router makes your LAN unreachable from a so called “external ip”. Just for the definition: external ip in this case is every ip that is not in your LAN. Imagine if your router would allow any communication without you explicitly giving permission. Every open port on your LAN would be available for the network that your router connects to. That is definitely not desirable.
Lets look at it with an example, quoted from this article:
your router has an ip of: 5.6.7.8 if you access it from outer network (internet)
your router has an ip of: 192.168.1.1 if you access it from your LAN
your laptop is in your LAN and has an ip address of 192.168.1.10 and you want to expose port 3000 from your laptop to the outer network (internet)
You have 2 options:
You can expose the port via the configuration of the router (e.g.: you map 5.6.7.8:3000 to 192.168.1.10:3000 in the router configuration and now it will be accessible from the outer network on 5.6.7.8:3000. Note that you can choose any free port, ports don’t have to match.). Of course it is only possible if you have the option to configure the router and you are willing to do so. (e.g.: if you are not in a café)
You can use some tunneling tools like Ngrok or OpenSSH, which make a direct tunnel between the external machine and your server. This can also work if you don’t have the ability to change the router configuration.
Hope I was able to help. Good luck.

Why doesn't my Node.js express Server work on other devices?

I have started my Node.js express server running on port 3000 and it works on my local computer the server is running on. Then I have forwarded the port 3000 to the IPv4 adress of my computer in my router but I still cannot connect to the server on other devices.
HAs it something to do with the protocol? Do you know why it doesn't work.
To connect to a server on your own local LAN, you need the following things:
The local IP address of the server. It would typically be something like 192.168.1.x, but in some cases it might be of the form 10.0.0.x.
You need to make sure the computer the server itself is on does not have any local firewall that is blocking incoming http connections. On Windows 10, there is a local firewall that by default blocks incoming http requests so you would have to enable incoming http requests on the desired port in that firewall configuration.
You can then connect to that server from somewhere else on your local network with a URL of the form http://192.168.1.x:3000/ where the 192.168.1.x is the actual local IP address of your server computer and the 3000 is the port the server is running on.
You need to make sure your other devices are actually ON your local network. For example, if it's a phone, you need to make sure it's actually connected to your local network via WiFi and not connected to the visitor's connection that can only reach the internet, not your local network.
You do not need to do any port forwarding in your router. That's something that would be done when connecting to your server from outside your network (like from the internet). I that case, you'd have to connect to your public IP address and have that safely port forwarded to your server. But, since you said you're trying to connect to the server from within your LAN, you don't need any port forwarding on your external firewall.

how to connect to a server running on computer using computer's IP address?

I am working on IOT project in which I have to change some variables(fans speed, lights, etc). So just as a starter, I created a node.js server and tried to send requests to the server through a local network using local IP as
http://localhost:7000/users=mandar?lights=OFF
or
http://192.168.43.248:7000/users=mandar?lights=OFF
and it works fine.
Now I want to do the same over the internet. So I got Computer's IP address from https://www.google.co.in/search?q=myip and tried to send a request to the following URL:
http://(IP_address):7000/users=mandar?lights=OFF
This time it keeps on loading and finally shows this site can't be loaded.
So what is the right way to connect to the server through the internet?
Thank you.
You have to do port forwarding.
The IP address you get from the google search is the out-facing IP address of your router. However, your router knows your computer by your local IP address (i.e. 192.168.x.y).
You have to configure your router to send packets coming from internet destined to port 7000(or any other port) to your computer's port 7000.
Check your router's documentation on port forwarding. Likely there is a settings page on the web interface of your router that you can do the desired port forwarding. After configuring the router, there are several tools online to test if the port forwarding is actually working. I suggest you use one of those tools to verify the configuration before testing with your project.
You also might want to check if your router has a firewall. You can add an exception to the firewall such that a specific port number is reachable from the internet.

Node.js & express how to open my rest api on localhost to remote partners?

My partners can send http requests to my domain, like this:
https://www.example.com/getrequest/
As my domain is public.
And I have also enabled CORS.
How to enable such a thing with my localhost during development?
I have tried to visit my Node.js server with my IP address in the url bar in the browser of a different device like this:
http://myip:8080
But it asks for the WiFi password.
How make my IP available for incoming requests, just similar to my VPS so it will be available to development with partners?
Thanks.
In order for your computer to be accessible from the internet you have to enable port forwarding for your router
Port Forwarding
The thing is that your router has a unique IP address yet many devices connect to it so they all share the same IP. The router with port forwarding links a specific device to a specific port so that you can access your computer from http://ROUTERIPADDRESS:DEVICEPORT from the outside world.

How to create a NodeJs server accesible from an external connection without port forwarding

I'm currently working on a project where I use a raspberry pi as a server for a home automation server. It works fine on my local network but if I want to use it from an external computer I need to forward the used port on my router.
I'm trying to find a way to make http(s) gets to the server without having to forward the port on the router. I want this because if I would install the system at someone's place (a customer maybe in the future) I don't want to have to access their router.
I've tried using SSL and https but I ran into the same problem.
Is there any way this is possible or is it a lost case?
PS I can't use port 80 since it is already in use.
Thanks in advance
There are two ways to get to the result you want:
Port forwarding, which you've dismissed
Giving the raspberry pi it's own public IP address (which requires a public IP address and access to the router to configure the traffic routing, which you've dismissed).
So let's go back to port forwards.
Most consumer routers these days support NAT traversal via uPNP.
You can use the nat-pmp module to reqest the the router forward a port for you, without having to have direct access to the router.

Resources