Node js on existing domain - javascript

i wanna use node js on my webpage, which is hosted by a company. I saw that you can run a local server on node js, but does anyone know how i can link it to my existing domain example.com.
As mentioned I saw that you can use express for this, but i dont know my port neither how my server reacts to my js code.
any recommendations?

To be able to access your locally developed node project from your domain name from any computer connected to the internet you will need to do something like the following:
Point your domain's DNS records to your server
Log into your domain name provider and find the DNS settings section, then paste in your servers IP address. Once this is done, visiting your domain name in the browser will connect the domain to your server which you control. Under the hood the browser can now successfully ask the domain name server (keeps records of domains and associated IP addresses) for the IP address to query which corresponds to your domain name. But thats not quite enough yet!
Install a server application on your server
A server is just a normal computer with server software installed which enables incoming requests to receive a response in anyway you define in the configuration of the server software. nginx, apache and express are all types of server software.
At this point you need to see whether the server you are renting supports nodejs as a server, if not you should look elsewhere for a provider that does. (not hard to find)
Install software dependencies to get your express server up and running.
EG:
node, npm, express

Related

Find the private ip of an express server

I have a node express server running on Machine 1 as (0.0.0.0) and some client applications running on Machine 2, 3, and so on...
All machines are connected to the same Wi-Fi
How can I get the private IP of Machine 1 (which is running the express server), so that I can directly start calling the server APIs from client applications?
Note : I am using electron js in both server and client
There are a couple possibilities.
You can assign a local IP address to your server that does not change and thus is known. For example, on my LAN, I configure the auto-IP assignment to avoid 192.168.1.200 - 192.168.1.255 and thus I can manually assign those IP addresses to devices for which I want to have a constant and known IP address. Then, you can just refer to the "known" local IP address from your clients as in http://192.168.1.201/somePath.
You can configure local DNS (probably in your gateway router) so you can access your private server from your private LAN using a DNS name and combine this with option 1 so the IP address of your server won't change. You will need a router with this capability.
You can use a resource discovery service such as Simple Service Discovery Protocol (built into Windows) or BonJour (built into MacOS, available for Windows) if your client has the capability to use these. Your server will advertise its services in the resource discovery system and the clients can query the system to find the server.
The short answer is that you can't. HTTP servers don't broadcast their addresses.
You need to run some other kind of service (on the same machine as the HTTP server) such as zeroconf to provide discovery.
Then you need the clients to use it to find the server. You're probably out of luck if your clients are written in browser-side JS and you'll need to go to another level of complexity. I think DNS-SD is the way forward there.

How to allow for a HTTPS request to local ip

I deployed a web application which require to send request and get response from a local ip(ie. 192.168.0.123), which is actually a payment terminal.
It seems that this violate the entire https purposes, however I have no control on the payment terminal and it's address due to 3rd parties API.
Are there any workaround to handle localhost/ local ip ith https request?
If you can install additional software on the payment terminal, then you could install another HTTP server that acts as a reverse proxy and listens on HTTPS.
You then make your requests to https://192.168.0.123 and your reverse proxy forwards them to its http://localhost.
Nginx is a popular server for this purpose.
If you can't install additional software then you should look at using an isolated network instead.
It doesn't really matter if communication over a local network isn't encrypted if you completely trust every device that is connected to it.

Proper way to connect two NodeJS servers

I am trying to build an app to retrieve data from a local database, The structure of the app that I have a mobile app, server(on a hosting service), and local server(on my pc), I am trying to make the mobile app request data from the server via a normal HTTP request then the server request the data from the local server but the problem that I could not be able to connect with my local server I believe that I could not connect to my local server because my local server does not have a public IP, so I am trying to find a better way to achieve my idea.
I read something about Websocket but I don't know if it suitable for my idea beacuse it is Bi-directional connection and It most used for chatting app
I want to build the app with NodeJs, so what should I do to implement this idea, and thank you for the help.
Each server is on a different network the main server is on Heroku host and the local server is on my personal computer
Life would be a lot easier for you if you move your local server to Heroku where they can much more easily and securely talk to one another.
You can't connect from your Heroku server to the server on your private local network because it is behind a firewall in your home router. To allow such a connection, you have to configure a known public IP address for your home network (that won't change or use DDNS if it can change) and configure port forwarding in your firewall/router so incoming connections from the internet on a specific port can reach your local server. You will then have to harden your local server against random internet attacks since it will then be open to the internet.
One other possibility is that you could have your local server connect to your Heroku server (perhaps with a webSocket connection using some sort of secret credential). Since your Heroku server is already reachable from your home network, this would require less networking configuration change. Depending upon what you're trying to do between the two servers, you could either have the local server just make a regular http request to the Heroku server (either sending data or asking for data) or you could make a webSocket connection and then data can be sent either way of the webSocket connection.

How to make requests from an external server to localhost

Is there a way that I can make a GET request from an external server (like google apps script) to my local server?
For example, I would like to make a GET request on this url: http://localhost:3000/api/get_data
If I do that then I get DNS error. Replacing localhost with my ip address gives Bad Request
The "localhost" address is not accessible from the Internet, so you can't use it.
Having your IP instead of "localhost" may work, that depends on the firewall rules of your ISP and on your local machine.
The easy way to expose your local machine to internet is either by using SSH (if you have the remote machine that is accessible from Internet, for example, Amazon EC2 instance). You can use -R ssh switch for that, something like this ssh -R *:8181:localhost:3000 remote-machine and you can use "http://remote-machine:8181" to connect to your app.
See also The Black Magic Of SSH / SSH Can Do That?.
Another way is to use service like https://ngrok.com/ that will do the remote part for you.

Putting Node.js/Socket.io Onto a Website

So I'm getting into working with node.js and socket.io to make real-time web games, but I'm running into some obstacles.
I've already figured out how to install node.js and socket.io on my computer, and I can run basic servers and open them through http://localhost:8888/.
But now what I don't understand, and there doesn't seem to be anything on the web that explains this, is how to get this onto a website. Obviously, someone else on the internet that enters that same URL isn't going to see the same thing as what's on my screen. How do I get this onto a webpage so that anyone that visits that URL accesses the server?
I tried opening the port and then using http://<my external IP>:8888 but that doesn't work. Some sources seem to say that I need to install something on the website, but I installed node.js on my computer through command prompt, so I don't understand how that would work on a website. I found instructions for Linux, but I'm running Windows.
What you need is a:
web server - to host your game. You can, for instance, rent an EC2 instance from Amazon and install there all software required (Node.js, database, ...) or go with PaaS (Platform as a Service) solution like Nodejitsu or Heroku where you'll be given Node.js out of the box.
domain - to register a human-readable name for your web serwer (like. www.my-game.com). Normally, once you get your server, it'll have some IP address assigned to it. Domain name is an alias for it, easier to type and remember. Similar to, as in your case, localhost is just an alias for an IP 127.0.0.1 (special address meaning local system).
Of course, another solution would be to host app on your local PC and set up your router to forward traffic from it's external IP to your PC (assuming your ISP assigned you public IP). But then you'll have to worry about your PC, router and internet link being always online. And it'd be way slower than when going with external, dedicated hosting.

Categories