How to allow extern access with node.js - node.js

How can I allow other users to access my application that is running on localhost? Is there any package in the npm that facilitates this access?

To access your localhost (on a home network) from the internet, you need to provide a couple things.
You need a way for your clients to contact your server. This can either be via an IP address http://xxx.yyy.xxx or a domain name http://somedomain.com/whatever. If it's an IP address, then it needs to be a public IP address (not a local network address). For a home network, you would typically use the public IP address of your router that is how you connect to the internet.
If you are going to use a domain name, then you need to actually choose a domain name, register it with a registrar and configure it to point to your router's public IP address.
If your router does not have a static IP address, then you will likely need to use a dynamic DNS service that will automatically update your DNS entry to point to your dynamic IP address whenever (or if ever) it changes. There are lots of dynamic DNS services.
Then, you need to create a "hole" in your router's firewall so that incoming connections to port 80 are port forwarded to the computer where your server is running. This will typically be done in the router's configuration/security administration UI. You will "port forward" and incoming request on port 80 to whatever IP and port your server process is running on your local network.
For a more durable server installation, you would do the following:
Buy a hosting package at a hosting site that hosts the type of application you are running at the scale you expect to run it at (storage, CPUs, bandwidth). In your case, you'd be looking for a hosting service for node.js apps.
Then, you'd buy a domain name and configure it to point to the public IP address that your hosting provider gave you for your server.
Then, you'd install your server app at the hosting site and run it according to the hosting provider's instructions.
Then, a user can access your server via an URL using your public domain http://somedomain.com/whatever.

You can do so by using ngrok. In your command prompt type npm install ngrok. Once installation finished restart your command prompt and type ngrok http 3000, here 3000 is the port on which your server is running. You will get something like http://ee309.ngrok.io which is your temporary domain. You can use it until you shut your system down or close command prompt.

Related

How to host a website locally but with .com domain and accessible on internet

I've bought a .com domain from a provider on the internet. But, I want to host it locally.
I know that I can host a local web by using XAMPP or WAMP, but I want to make it accessible on the internet.
I also know that we could host a web to be accessible on the internet like ngrok, serveo, etc.
But, I want it with my .com domain that I bought. Could this possible? How to? Is there any references?
Thanks in advance ^_^
It seems to me you are asking 1. if it is possible to map a DNS entry such that traffic to the URL would be directed to a server in your personal network, and 2. if it is possible, how to do it.
The answer to the first question is yes, it is possible. The second question is difficult to answer because it depends on many factors such as your ISP, country, your web host provider's rules and services, etc.
First, you must determine two IP addresses:
The public IP address for your network (whatismyip.com)
The private IP address of the local machine which will host your website (typically (192.168.0.x)
Then, you must enable port forwarding in your router configuration, such that any requests to port 80 and/or port 443 on the external interface (public) will be forwarded to the internal port on which your website is hosted. If done properly, putting the public IP in your browser will take you to the website you are hosting locally.
Once you verify access via public IP, then you must go into your DNS entries on your domain host and create a CNAME record which points your root domain (www.yourwebsite.com) to your public IP address. That will route all traffic to your .com to your local server.
I do NOT recommend doing this however, and would caution against it, because it leaves your local server/network open to the public, and makes your domain vulnerable to things such as spoofing etc. To do it properly, you should obtain a security certificate for your domain through a Certificate Authority (CA) - generally, you can request a certificate via your domain hosting service. Once you have a certificate, you must upload the key to your server and configure your web application/hosting service to use the certificate, and then change your port forwarding to use 443 instead.
This is a very complex topic that takes time to learn, and your question is extremely non-specific. There is no good place to start really, and no shortage of information/resources available online. To start, you need to understand how your DNS works. For any local webhosting, port forwarding is important to learn. You should also determine if your ISP blocks the forwarding of certain external ports, which effectively disables any private webhosting.

How to redirect a HTTP request to localhost on windows?

I've created a node.js app. When it runs my mobile phone can connect to it using address 192.168.1.5. In other words, when I open a browser on my phone and enter 192.168.1.5 I get a welcome page served by the app running on my PC.
The problem is that the IP address is not human friendly. Is there a way to access my app by an alias? For example, http://myapp or something like this?
Yes, these aliases are provided by the domain name service (DNS). You need to set up a hostname on DNS to point to your machine's local address.
Put that IP address into a DNS server.
Here's a free way to do that.
Create a FreeDNS account by visiting https://freedns.afraid.org/
Click on Subdomains.
Click the Add link.
Create a subdomain hostname under one of FreeDNS's public domains. Maybe mydev.manidos.mooo.com is a good choice
Put your machine's IP address into it.
Then, use https://mydev.manidos.mooo.com to hit your development machine's nodejs app.
You can pay FreeDNS to register your own domain name and use that if you prefer.
There are all sorts of other ways to register a domain and then add address records to it, to translate from hostnames to IP addresses.
Edit If you were connecting to and from your desktop / laptop machine, you could add a hostname to your hosts file. The hosts file is itself a little DNS registry that's local to your machine. On windows it's at C:\Windows\System32\drivers\etc\hosts. On *nix and mac it's at /etc/hosts.
But, you are connecting to your app from a mobile device. Editing the hosts file in a mobile device is unreasonably difficult.

Change NodeJS local server access URL

Is it possible to change the URL used to access my local NodeJS server?
For instance, I have a Node server running on port 3000, so I can access this server directly through:
http://localhost:3000/
And other users on my network can access it through:
http://[MY_IP_ADDRESS]:3000/
Is it possible to forward this server to a local URL, like http://example/
I know that, in order to remove the port from the URL I need to bind the app on port 80, but I can't find anything about changing de URL.
Not very clear what you want, to be honest and your set-up. You use local computer or server in local network?
If you want URL in your local network isolated - that's not possible hence the URL protocol forwards requests from domain name to certain ip address.
If you want only internal access in your local network you only need to know your local ip address and make sure your firewall allows local connections. Depending on your OS run ip check in cli and voila - that's your ip.
If you want external connections then you need to have a static ip address which you should obtain from your internet provider and afterwards you need to alter you router settings and set up port-forwarding to your local machine. It will then listen to external connections on certain port and forward it to your local machine where nodejs listens (itself or through web-server). Here you can redirect your domain URL name via A-record to your static ip address of your router and port-forward to local machine.
Check out this guide for most routers for external port-forwarding.
UPD: checkout this answer

How to use iis with friendly name on local network

I make a web site to my local. I set bindings local.com and www.local.com. I add hosts xml to
127.0.0.1 local.com
127.0.0.1 www.local.com
So, I can connet on my pc like
local.com,
www.local.com,
192.168.1.35
But another pc on my network can't conenct with friendly name
www.local.com,
local.com,
But same pc can connet with ip
192.168.1.35
How can that another pc connect with friendly name ?
IP Addresses are the numerical identification for each device on a computer network.
Named Addresses invented, because remembering each device Address's turned to a difficult job.
So someone must know's which names must be converted to which IP Address.
DNS Servers are responsible to do this translation. But you done that locally. Actually you don't have a DNS Server on your local System, So you can't tell to others that "WWW.Something.COM" is my Address.
If you didn't connected to the internet, you must establish a DNS Server or done this task manually in all clients:
https://helpdeskgeek.com/networking/edit-hosts-file/
Running a DNS Server is another task. you can search for DNS Server applications like https://simpledns.com/ or you can setup a DNS Server using Windows Server. for both scenarios you need to tell to your clients to add your DNS Server Address to their network Adapter settings.
or If you are connected to the Internet, you can Use a NoIP to register a free Address:
https://www.noip.com/
you then need to download an application (In Noip.com) to monitor IP changes, it will monitors your IP address and it changes and then tells to NOIP.com to translate your address into your current IP address.
Actually NOIP will registers your address globally around the Internet network and each one who can access to the internet is able to reach to your address.

DNS not resolving outside intranet

We are installing a security camera system in our company which comes with a DVR that hosts a website on which you can view the cameras via the web.
I have setup the DVR with a static IP of 192.168.120.199 on our network and can view the website while on our network (either when at work or logged in via VPN). The camera DVR uses port 80 for viewing the webpage and port 9000 for Media Port.
We use GoDaddy to host our DNS info and I have added an Host(A) record of 'cameras' that points to the address of our server. I have also added a forward lookup Host(A) to our domain's DNS manager of 'cameras' that points to 192.168.120.199. When I use the address 'cameras.mysite.com' within our domain the website displays properly, but when I try the same address from outside our domain (ie, at home) it displays the default IIS 7 page (from our domain server).
Two questions about this setup:
Why does the forward lookup work when inside our domain but not outside (why does it go to the IIS default page when outside the network)?
How do I get this to forward correctly if not via the forward lookup host?
Because internally you're looking it up on your internal DNS server and you get the right 192.168.x.x machine. When you look it up externally GoDaddy is giving you back the 192.168.x.x, but that's not a publicly routable IP, so doesn't go anywhere. If you really want to be able to connect to your security cameras from outside your facility then I suggest setting up a VPN for security reasons. But if you want GoDaddy to directly route to your internal machine from the public internet then you'll have to give it a publicly routable IP.
As a further note on that - 10.x.x.x, 192.168.x.x and 172.16-31.255.255 are not publicly routable. They're called private IP blocks.

Resources