How to setup an API server with no domain name - node.js

I've been struggling to understand this because I don't quite know what to search for. Basically, I'm working on a simple node server that just works as an API that is to be consumed by a mobile application. I'm planning to deploy it to DigitalOcean but since I don't need a domain name because I don't have a website, how will I send the HTTP requests to the server? My guess is something related to the droplet's IP but that doesn't seem quite right.

Just send requests to IP address and port from your mobile app. like GET http://54.54.32.23:3000/user-newsfeeds/15

Related

How does one connect to a digital-ocean server from a local React project?

Background
I am working on the front-end of a project using React. The backend is saved on digital ocean, something for which I am a complete novice at, however I have made attempts to read as much as possible. I would like to be able to connect and make calls to the server from my local React project while I'm developing and testing. All that I have been given is the login details to the digital ocean droplet. My problem is that I am not sure what url/endpoint to use to make these calls.
What I've Tried:
Making calls to the ip that was given to me for accessing the droplet. e.g.: "http://148.41.158.149:8080" - this is not the official ip, just an example. I found out that this is wrong.
Using root#projectname:~# nslookup localhost, I used the ip given which didn't work.
I did manage to download the backend from the server and I can make calls to "http://localhost:8080", however I would like to know how to make calls to the server.
From what I understand, I need to retrieve the url for the server from the actual account. Is there any way to get this from the droplet?

Need Node app to watch external website instead of localhost

I'm still new to Node, so what I'm asking may not work the way I'm wanting to, but, here is my dilemma.
I have a website which has an old data collector (which I did not write) collecting data. I wrote a Node app that mimics the old data collector so that it can be replaced. But now that it's ready for testing, how do I point the Node app towards the website and not localhost? The Node app is going to be hosted in a secure server.
When I would test in Postman I would test the functionality for, say, the 'id' endpoint by checking
localhost:3000/id
but now I want is when a user on the website goes to an address such as
www.myexample.com/id
The code in my Node app will run. And I may be wording this wrong, but basically if one of the endpoints is hit, I want Node to run the code for that endpoint.
The code for my endpoints is along these lines:
router.post('/id.json', function (req, res, next) {
//do the things
}
Is there a way to have Node work this way with an external website? I've checked, but haven't come across anything that would work for this particular issue. I'm using Express and I've tried changing my app.listen, to
app.listen('www.example.com')
but I'm getting errors from there, so I'm not sure if I'm not using proper syntax or if this simply isn't what app.listen was intended to do. Ultimately, what I'm wanting to do is have the Node app work the same way with the website as it would with localhost.
You can't take any site name by just "listening" to it with node app. When user in the Internet goes to www.myexample.com/id, the url is resolved into ip address and user's browser connects to a server (physical machine) that is running on that ip address. This server then accepts the connection and serves the website back to user. If you own www.myexample.com domain name and the server this domain name points to, you should go to the server, take down whatever is hosting your current website and run your node app there. Your node app doesn't even know which website address it's being hosted on, all it cares about is accepting incoming connections and returning data. Also mind the port - http and https work on ports 80 and 8080 respectively (which are omitted in the url) and your node app, based on your description, is running on 3000

How did an IP send Get requests to my code?

I am new to web development. I am developing a flask web server on my linode linux web server on port 5000. I got this output from an unknown ip. I researched the ip and found out that this is a whitelisted IP address and is "harmless", but I dont know. It looks like it sent GET requests to my cover photo, the javascript, the css, an icon on the page, and an unknown request. What does sending a GET request to these items even entail? I dont have any button or anything that sends a get request to these items. Whenever I am developing the web server while on port 5000 I am usually the only IP on the output. Additionally, this web server communicates with a raspberry pi over mqtt over the non-encrypted port 1883.
Again, I am new to this world and am wondering if anyone can help me decipher what this means that would be very helpful. In the meantime should I will configure the servers firewall to only allow requests from my computers ip to my server? Anyone think this is a reasonable next step or have any additional advice?
I believe what's happening is that your website is sending a GET request to retrieve those assets (e.g. your images) which are stored under your localhost address and the paths that you see in the console output.

Does a Node js web server need a domain name to communicate with clients on other devices?

I am working on a swift project for osx with Firebase. I have a node web server to communicate between the clients and the Firebase-server, but it's a localhost-server. Do I need a real domain name to make the server accessible to end-users on another device? (I don't want a web app, just the backend for myself)
you doesn't need a domain .. but you need a serve to deploy having ip address .. suggestion you can use cloud server
You have two ways:
make request on port that the nodejs uses, example http://101.01.01.01:8000
use nginx like proxy, in this setup make your requests on 80 port (it's default), example http://101.01.01.01.
If you wont make something like dev environment on local machine use first case (don't forgot open port for other devices), for production - second.

node js send html to network rather than only localhost server

I'm using node js trying to send my web-page to my network, I successfully call localhost:port in my computer using express as server, the webpage loads fine trigger my webcam which I used to streaming in the webpage, and then im working to make a simple app in my phone to directly access my server, so my questions:
1.How do I able to access my server from different devices in the same wireless-network? by calling ip + port ?192.168.1.104:9001 ? cause i've tried and it didnt work.
2.I've found https with .pem something like that, is that the answer ? is there also any other way ?
3.maybe any advice before i work to make my web-app to devices? using koa? i don't even really know what is that, but i'm happily take any advices.
EDIT: i've read How could others, on a local network, access my NodeJS app while it's running on my machine?
let's say I simply using random router, so i can't configure my router-port, my server in my pc and my phone join in the same network, trying to access the server in my phone
1.How do I able to access my server from different devices in the same wireless-network?
All you need to do is find your server's IP address in this same wireless-network, and find the Node.js application's port. Then access the following URL in other devices:
http://{server_IP}:{port}
However, there are some points need to check:
Need to check firewall and confirm the port is not blocked, server IP is not blocked by test device, and test device IP is not blocked by server.
Need to check whether there is any Proxy setting in server and test device. If there is any, disable the proxy.
A computer may have many IP addresses at the same time, you need to find the correct one in the same wireless-network. For example, If you install a virtual machine software such as VMware and run a virtual system inside, your real computer will get IP address as 192.168.*.* -- this IP address looks like an intranet IP in wireless-network, but it is not, and can never be accessed by test device.
2.I've found https with .pem something like that, is that the answer?
No, HTTPS has nothing to do with this problem. HTTPS just add security (based on HTTP layer), it does not impact any HTTP connectivity. Actually, to minify the problem, it is better to only use HTTP in your scenario.
There is only one very special case that may bring your problem by HTTPS -- the test machine is configured and will block any non-HTTPS connection for security.
3.maybe any advice before i work to make my web-app to devices? using koa?
My suggestion is: As there is an HTTP connectivity issue, the first step is trying to find the root cause of that issue. Thus, it is better to make a simplest HTTP server using native Node.js, no Koa, no Express. In this way, the complexity of server will be reduced, which makes root cause investigation easier.
After the HTTP connectivity issue is fixed, you can pick up Koa or Express or any other mature Node.js web framework to help the web-app work.
4.let's say I simply using random router, so i can't...
Do you mean your server get dynamic IP address by DHCP? As long as the IP is not blocked by test device, it does not matter.

Resources