How to access localhost:3000 on AWS through NodeJS server - node.js

I have a node js server set up on AWS using Linux instance(Ubuntu 14.04) I have started the server using the command npm start How do I access the localhost:3000. And when I do it locally I am able to access all the webpages by going to the browser. How can i access it when the server is on cloud?

The localhost host name is resolved to IP address 127.0.0.1 (or IPv6 equivalent) which is routed to the loopback interface so that you cannot reach any other host than your own with that. That's why it's called localhost in the first place.
To reach your host from the outside you need to know its external IP address or a domain name that resolves to its external address. You should be able to see your external IP in the dashboard. If you can't then see this answer.

Related

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

Can't connect to localhost on my application server but can access it via web

I have a website which is accessible via its URL but strangely i cannot connect to it via localhost on the server itself.
I have ensured that "127.0.0.1 localhost" is in my hosts file
I have checked that no other application is using port 80
I've ticked "Bypass Proxy Server for local addresses"
Pinging my local host from command line returns data When you go to the domain host URL the application loads successfully
Good news is my site is fully functioning but i just cannot figure out how to connect to it on localhost in my browser! any ideas?
Added details as requested;
Its a website not app if that was misleading.
The webserver is IIS on an Amazon EC2 windows instance.
The root URL is just a simple html page, which i can access via the domain URL.
However when i RDP onto the Server itself and try to access the localhost, it continually blocks me, the page wont load.
It is possible that your application is only listening on external IP address. To bind your application on all IP address, you may make your application listen on 0.0.0.0.
And could you please show the related code to help locating the problem?

What IIS or network config is necessary to be able to use a network alias from the host server?

Our web server hosts some APIs that other apps running on the same server need to call. These calls are failing with a 401.1 error.
The server has a single IP address. The server name and the network alias we use both ping to this same address.
I can browse to addresses on the server from other computers using either the machine name or the alias.
If I connect to the server I can't browse to any addresses using the alias. The machine name works locally but not the alias.
If I use the alias I am prompted to to login with my credentials. These are not accepted and then leads to 401.1 error.
How can I configure the server and/or IIS to allow the network alias to be browsed from the same server that the alias links to?

Invalid Host header when trying to connect reactjs and domain name

I'm trying to deploy a JS app (back in nodejs, front in reactjs) on a hosting server. I've dockerized everything (back, front and database) and everything works well, I can access my app through the IP address of the server.
Now I'm trying to setup a domain name to point to my app.
I've a Invalid Host header when I try to access from domain name (while still working accessing through server's IP address).
I've tried to add a HOST:mydomain.com to the .env of my reactjs app but I got this error Could not find an open port at mydomain.com
Would love if someone can help me through this :)
Given app works by IP, you can leave config of app as is. Do not add HOST or any other config.
IP to name mapping is done using DNS. So made DNS registration in DNS zone like this
mydomain.com A <IP address of app>
Where A is DNS entry type. Or made request to provider to register A entry type for you.
For testing purposes you may do mapping on any Windows PS using hosts file C:\Windows\System32\drivers\etc\hosts where mapping is done by
<IP address of app> mydomain.com
hosts works on one PC only.
After adding to hosts or to DNS try ping mydomain.com to make sure that name is resolved to correct IP address.
Mapping on web server is done when one web server hosts several different sites on one IP. But when you use Docker it's best to have one Docker container for one service.

How to allow extern access with 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.

Resources