How To Get The Server URL?


This may seem like a basic question, but I’ve been having trouble understanding how to do this.

I am pretty comfortable using fetch() and GET requests on the client side, but I am kinda lost as to how to create a server URL for clients to send requests to.

const host = 'localhost';
const port = 8000; 

So a local client can send network requests to http://localhost:8000, but what about remote requests? I feel like I would need to create a server URL for remote clients to use as a destination for fetch() and XMLHttpRequest() requests.

Once I deploy my server.js file to a provider, will they give me a URL that I can then assign to the host variable, and would that be enough to allow remote clients to access my server.js script using network requests?

I would super appreciate if someone could ELI5. Thank you!

of course, when you deploy your server to a provider such as Heroku, Render, etc… . they will provide a Url that you will provide to your client so that they can use to communicate to your server like fetch('')

This is an article about deploying node.js server with Render for free

I believe I understood your question and answered accordingly,

1 Like


Thank you very much.

1 Like