JSON Data not appear in another computer - javascript

I tried to fetch JSON data from the API with http://localhost:3030/get/articles and the data was successfully displayed on my reactjs, but when I tried on another computer the JSON data did not appear, I used axios to get the JSON data. Has anyone ever experienced or been able to help my problem?

Localhost is just a local server built on your own computer machine. Which can be used to host website locally for testing it.
If you want your project to be accessible from other computer, you should install your project on a web server with registered domain name pointing to this web server.

Localhost is a local server built on your own computer to development and testing. so if you want to access your application another users, you should published to server side computer or cloud.

The problem here is that you're accessing localhost which means the local machine.
When you try to access localhost in your web browser, you're basically saying this computer. If you do it on the machine where you develop your application then it will work but on another computer it wont.
A solution to access your JSON from another machine could be to use the IP of the machine that provide the JSON instead of the localhost keyword.
Like this: http://IP_OF_THE_MACHINE:3030/get/articles.
E.g.
http://192.168.10.12:3030/get/articles
You can get the machine's IP by typing ipconfig (for Windows) in a Command Prompt.
You can use a DNS entry or edit the C:\WINDOWS\system32\drivers\etc\hosts file on Windows to avoid typing the IP address everytime.

You can run ssh -R 80:localhost:8080 ssh.localhost.run. where 8080 is your port number. Yours should be along the lines ssh -R 80:localhost:3030 ssh.localhost.run since 3030 is your port number.
When you run this in your terminal you will get a message Connect to http://dummydata.com.localhost.run. Go to that link and basically you'll get your stuff online.

Related

How can we access Node server outside the network if the app is listening on 'localhost'?

Using Express when we use app.listen(port) , the app location is localhost:port/
In local machine I completely understand how we can access to this address as we use a local browser running on same machine . Even other clients running on same network can access the server.
As per my knowledge localhost or 127.0.0.1 IP can be accessed on same or other machines in same network.
But if we deploy to cloud like Heroku without adding IP option like app.listen(port, IP_ADDRESS) instead we use app.listen(port), the only thing that varies is PORT number(process.env.PORT) but IP is still localhost. So how can clients from other networks access the server?
You can use port forwarding on your router to forward router_ip:port to local_ip:port allowing you to access it externaly
Just because you are connecting to your local instance via localhost doesn't mean it is not also exposed via IP. Localhost basically says don't resolve any IP, just loop back to this computer, but your node server will still be deployed to an actual IP address. Try looking up your computer's IP address and connecting to your node server through that instead of localhost, and you'll find you're still able to communicate with the server.
When deploying to a cloud service, or any other hosting service, you'll be given an IP address associated with that instance which is what will be used for resolving. Heroku in particular will blackbox a lot of the domain-space and port-forwarding process for you.

How can I make node.js run in a normal web hosting like GoDaddy

I don't know if this question is the most appropriate way to ask it. But I am really confused on how Node.JS works. I consider myself an advance JavaScript user/developer but I cant get a knack on how to implement Node.JS as a replacement for PHP.
I have been used to developing sites with PHP as it's backend. But now I want to change to Node.JS. Now I'm really confused when watching tutorials about node. I've seen that it always needs cli to be open, and when a user visits your site, do they need to enter port number into the URL in order for the node script to work?
Another question (if I hadn't already asked a million of them) is node.js considered safe if I use it as backend and put my Database details into the script? I'm just confused because if you enter the app.js path into the URL, the user can see all it's content not like PHP.
Thank you in advance!
If you are a NodeJS beginner and looking to host your app somewhere I recommend using EvenNode or Heroku to host your simple node applications until you have a better understanding on how NodeJS works.
Some docs on node hosting on these platforms
EvenNode : docs
Heroku : docs
To answer your other questions :
when a user visits your site, do they need to enter port number into the URL in order for the node script to work?
It depends on your setup. You can choose to run your node application server on a specific port or can always opt to run it on port 443 (https) or port 80 (http) and the client certainly wouldn't need to specify a port in the host name.
is node.js considered safe if I use it as backend and put my Database details into the script?
Yes, NodeJS is safe. NodeJS is server side language just like Java, C#, Python, etc. It is safe so long as you don't expose any sensitive data, such as database connection information, publicly. The only reason you can view your app.js via (im assuming the browser) locally is because you are viewing it as a 'file://'. when this code is ran as a server, the server side code will not be viewable to the client.
You want a hosting with root access for Node.js.
So you want a VPS or Dedicated Server at GoDaddy.
The user does — not — have to enter the port always.
If you set it to 80 for http and 443 for https it works so.
You can have the main script in another directory.
Like that it is safe to enter database details.
The user cannot get the script then.

Nodejs connection bug with ip redirection

I have a problem with NodeJS (I think) using a kafka node on a node-red instance installed on a RPI3.
Scenario:
I have a cluster with a running instance of Kafka. The real ip of the machine which host the kafka broker is private so I have a public ip with a public port which I can use. Then, the requests are redirected to the broker.
Testing my environment with a broker installed on my laptop (so knowing the real ip of the broker) everything works fine.
Performing an attempt on the real cluster node-red shows the problem described in the terminal:
So, I took a look in js file representing the kafkaNode I used and I find this:
I'm quite sure the problem is in these line and in the use of the ip redirection. Anyway, honestly I'm a newbie of Nodejs and javascript so I don't know if there are some bugs about use of it.
Any ideas?
P.S.: I'm sure that kafka broker is correctly running and installed. the problem is exactly in js.
I also tried to reach the "fake ip" with telnet, and it works fine.
Thanks in advance
Kafka does not work with default values configured if you use a NAT, VM, or other proxy for "ip redirection" because the clients dynamically discover the private IPs of the real kafka brokers and will try to connect directly to those IP addresses and not just the one you configure in your client for the initial connection and meta-data request.
You need to make sure that the broker is setup to advertise the hostname or IP of the machine doing the redirection or your producers will not work.

connect to node server finding the mask automatically

so this is my problem:
I have a node server with a game i'm creating. the node server is listening in a ip mask that is given to him in network, like 192.168.x.x (isn't always the same).
The game 'frontend' is a web page, in a domain (like paperplane.io) that points to my dropbox project and makes it accessible.
How can I make my game frontend, the client, know behind what mask is node server listning, in that network, so it can communicate with it with no specific configuration.
Synthesizing: start node server in local network. every device in that network can access it via web url. plug & play.
thaks
Ok, so i solved my problem by having my node server sending updates to a mysql database with something like: I'm XPTO and I'm at 192.169.X.XX.
so, when i access my application i tell her what i'm looking for (i always know) like this:
XPTO.application.com
by the subdomain i check the database for key:value and get my nodejs ip mask in network.

Node.js server to webapp connections

I'm running a game which contains a server.js backend (which is hosted and run on my localhost), and the frontend is on a github website. The github page connects to the server on my localhost through the config which points to 127.0.0.1. I realize that I will be able to play this from my localhost this way, but will other people be able to?
Basically the index.html connects to the visitor's localhost to look for the running server.
A visual representation (sort of):
[nullwalker.github.io/index.html] ----> [localhost(127.0.0.1)/server.js]
What should I do to allow myself to play from the computer that's hosting the server backend as well as others being able to play?
You would need to host it in a live environment. There are ways via port forwarding to use your computers ip (gateway) to allow others to connect, however typically ISP's will try to stop you from using your dynamic IP statically. Safest bet is to launch a cheap VPS and host it there.
http://www.howtogeek.com/66214/how-to-forward-ports-on-your-router/
This article seems to explain port forwarding well enough.
As for the VPS, you can find extremely cheap ones really easily, if you do not expect a lot of players it should be fine, if you expect more then using your own connection is dangerous.
unless they have the same server running on their localhost, no. And they almost surely don't. You should get a host (digitalocean.com is very popular and good, but there are many others), and then run it there and connect to that instead of localhost

Categories

Resources