Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Understanding of the HOST variable in .env and different URL on start

See original GitHub issue


I’m creating a tool for websites using CRA. This tool is being loaded in an Iframe inside the websites. So when developing, I use a site which loads an iframe under localhost:3000. And it all works perfectly. The only thing I would like to do is when running npm start, the site would be opened, instead of localhost:3000. I’ve learnt I could apparently use the HOST env variable, but I don’t actually think it’s supposed to be used for that purpose.

From what I understood, this is more a variable used for webpack to listen on a different URL, am I wrong? Plus, when trying to add it actually loads which is not really what I would like.

Could anyone guide me or maybe it should be a new feature request? In that case I could try to fill in a PR.

We could also have the ability to use a URL like URL_TO_OPEN=HOST:PORT?param=value so CRA could replace the HOST and PORT by what it’d be using and give us the ability to add query params by default.


Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

Timercommented, May 20, 2017

You are correct in understanding that HOST affects what the webpack dev server listens to; it will alter what is opened but will also alter what we try to bind to.

To achieve what you’d like, you will need to use the custom node script like so:

// launch.js
delete process.env['BROWSER']

Then create a .env file that contains this:


Running npm start should now do what you desire (no HOST var). 😄

You can override the URL_TO_OPEN by simply running URL_TO_OPEN="" npm start instead, but the .env can be a default.

Timercommented, May 21, 2017

Unfortunately, networking doesn’t work like that. 😅

Closing this since the original question by @fbarbare has been answered, @cr101 if you have additional questions please create a new issue so we don’t blow up @fbarbare’s notifications.


Read more comments on GitHub >

github_iconTop Results From Across the Web

Server doesn't work with HOST variable in .env (Create React ...
Solved it by adding custom.localhost in my /etc/hosts in addition to adding the domain to the .env file.
Read more >
Environment Variables: What They Are and How To Use Them
You will learn some popular ways to create and manage environment variables and understand when to use them. By the end of this...
Read more >
Using environment variables in React | by Sam Pakvis - Medium
When you run your command now, everything gets compiled and your process.env.API_URL will be compiled to the correct url, based on your environment...
Read more >
Environment variables set by HTTP Server - IBM
Variable Name Type Description QZHBIS_CLUSTER_ENABLED Non‑SSL REDIRECT_QUERY_URL Non‑SSL HTTPS_SESSION_ID SSL Set to NULL by default when used with HTTP Ser...
Read more >
Easily detect what host environment your code is running in
host.env. This property is an object containing environment variables as key/value strings. When running in Node.js, it is set to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found