title: ReactJs How to pass custom server hostname?
body: <p>I want to be able to pass a custom server hostname when running my react app to be used in the url when I need to fetch data. The server is currently running on my local computer, so when I fetch(url) I've been using "<a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>:...." which has worked perfectly. But I want to be able to have to pass a custom host name, such as my ip address, to be used in the url (i.e. <a href="http://ipaddress:.." rel="nofollow noreferrer">http://ipaddress:..</a>.).</p>
  
  <p>I've tried starting my app like this:</p>
  
  <pre><code>serverhost=ipaddress npm start
  </code></pre>
  
  <p>and then in my package.json file</p>
  
  <pre><code>"scripts" : {
     "start": "react-scripts start $serverhost"
  }
  </code></pre>
  
  <p>and in start.js I can access process.env.serverhost, but I want to be able to access the host name in the browser for my actual fetch calls. I don't want to set the hostname in "config" in package.json or in an .env file because it has to be able to change (I'm under the impression that this isn't possible). I just want to be able to access the server host name given as an argument in the command line in my src files.</p>
  
  <p>(I read somewhere about doing</p>
  
  <pre><code>REACT_APP_MY_VAR=test npm start 
  </code></pre>
  
  <p>and then accessing it as</p>
  
  <pre><code>process.env.REACT_APP_MY_VAR
  </code></pre>
  
  <p>in the src files but when I tried to fetch(url) I got a bunch of failure to parse URL errors)</p>
  
  <p>EDIT: I tried using REACT_APP variables and I no longer got parsing URL errors when fetching</p>