How can I get the hostname and set it in a variable? NodeJS

I want to get the hostname and then set it to a variable.

Use case:
The email to reset the password is something like www.hostname1.com/?email=bla@bla.com&hash=xyz

I want to change it to a variable, so when I publish to another target it still works:
www.hostname200.com/?email=bla@bla.com&hash=xyz

I’m attempting to put them in the Globals in a server action and then put that server action on the page, but I don’t understand how the Globals work. (trying to do something similar to this guide)

The globals can be different depending on the web server and language used.

$_GET are variables from the querystring
$_POST are variables from a form post
$_PARAM are variables from the route parameters
$_SESSION are variables from your server session storage
$_SERVER are variables from your web server
$_ENV are variables from the server enviroment (OS)
$_COOKIE are variables from cookies
$_ERROR is keeping the last error object

For the hostname you would probably need to use $_SERVER.

https://www.php.net/manual/en/reserved.variables.server.php

@patrick Thank you so much!

I can see I would use ‘Remote_HOST’ according to your link:

  1. Is this the same for my NodeJS project? If not, is this it? https://nodejs.org/api/http.html#http_request_host

  2. Referring to the screenshot above: is this the correct way to grab that global variable and put it in a server action? By simply creating a Variable under Globals → $_Server

Thank you for clarifying!!

NodeJS is different, but we tried to keep them in sync with the PHP/ASP variables, so most variables will be the same.

REMOTE_HOST will return the hostname of the remote client, the client that is connecting to your server. It is not the server address.

You will need SERVER_NAME, that will contain the server hostname.

Thanks you @patrick.

I’m trying to get it to show on the page with these steps, where am I going wrong here?

Or should I use one of these two options?