Override HOST var ?

Hello all,

I have a (hopefully) simple question: is it ‘safe’ to override the HOST environment variable ?

Yesterday, I started a React JS development course. With default configuration, the dev server hosts the app on localhost:3000, but it reads the $HOST variable for this.
On my system (Leap 15) - both $HOSTNAME and $HOST vars are set to something like ‘linux-xxxx’.

Is it safe to permanently set $HOST to localhost without messing up my system ?

TIA :slight_smile:

This is a bit bewildering. HOSTNAME is set by the shell (bash) from the hostname as defined in the system (and as set during installtion, or changed thereafter). I do not think that it is wise to set it’s value different (where?) from what it should be. Many programs may use it, this the side effects may be serious. About the same for HOST.

You can of course change your systems hostname, the best way is using YaST for this (because YaST will not forget to change everything that should be done). But then again, I do not think it is wise use localhost as your hostname. Better see localhost as a reserved name that resolves to 127.0.0.1. When your ‘real’ hostname is also localhost, it can not be resolved to the IP address the system has. It is one of both.

But the start of all this seems to be

Yesterday, I started a React JS development course. With default configuration, the dev server hosts the app on localhost:3000, but it reads the $HOST variable for this.

Can you please explain more? A server process (daemon) normaly listens on a TCP (and/or UDP) port of the system, not on localhost.
A client process cab then connect to it using the IP address and the posrt number. When the client program is on the same system as the server process, the client can use localhost (whicg then resolvs to 127.0.0.1) as the IP address to connect to.
Thus the connection between $HOST (a variable that is set in the shell) and what the deamon uses for what is unclear to me.

I am using “localhost” for the hostname on one of my systems. It’s actually Tumbleweed installed to an external USB drive. So I use “localhost” to avoid confusing things if I move it around between machines that I boot.

However, I set that name by editing “/etc/hostname” rather than by directly setting $HOST.

Hi
From a quick search it seems it asks for “http://localhost:3000”, so in your /etc/hosts file should be an entry;


127.0.0.1 localhost

If it’s going to $HOST, then either the entry is missing, or you have it aliased in the hosts file…

Thanks for the replies :slight_smile:

Maybe my poor wording was confusing… client and server are the same in my case. This is the React tutorial that I followed : https://facebook.github.io/create-react-app/docs/getting-started
I’m not 100% sure how the app is launched (Webpack I guess ?) because all the configuration is done behind the scenes, and I just started yesterday :stuck_out_tongue:
All I understand is that the ‘server process’ (webpack or Node or whatever) is trying to bind the $HOST variable to ‘localhost’, which it can’t because it’s already set to something else.

I found a work-around though, I changed the default start command from “react-scripts start” to “HOST=localhost react-scripts start”, it seems to work that way without changing anything system-wide.

So this is more of a development environment configuration issue, not really openSUSE-related, so I’m gonna leave it at that :slight_smile:

To me it looks as if they are misusing the HOST environment variable. They use it for their own purposes. While there is no central organisation that registers environment variables, it is rather stupid to use one that is very well known to be used by all sorts of shells for another purpose already.

The best way to use environment variables for your own application is e.g. by adding the acronym of your application in front of the names. Like REACT_HOST, if you understand what I mean (maybe REACT_SERVER_HOST points better to the purpose of the variable). Then clashes like we have here are avoided and people will see the grouping of the variables.

As for your specific situation,
Reading your link to the React setup, I don’t see where it’s referencing the $HOST or $HOSTNAME variables at all. I’ve run similar setups and generally run the npm setup (maybe you’re running something different?)
When I run that kind of setup, “localhost” should always work <not> because it’s the $HOST or $HOSTNAME (of which neither should be “localhost”), but because you should have an entry in your /etc/hosts file for “localhost”
When the setup does use the $HOST or $HOSTNAME variable (which isn’t in the reference you used), yes you can change your $HOST or $HOSTNAME to something valid (not localhost! Can’t repeat that often enough) before you run your setup.

Similarly, you can create any other entry you want in your /etc/hosts file pointing to a valid IP address your webserver is running on, and it should work.

TMI -

the $HOST and $HOSTNAME variables are simply aliases that your machine uses to identify itself by name using Hostname resolution. The only place those variables can be guaranteed reliable is on the machine itself, in some cases those will also be used to identify itself to others on request which is why these should never be “localhost” because they would cause confusion on the remote machine. But, the machine can really be known to remote hosts by any name that is configured to point to your IP address (or other networking method), eg by DNS Server.

TSU