0
<configuration>
  <appSettings>
      <add key="REACT_APP_SERVER_URL" value="http://hostname.api" />
  </appSettings>
</configuration>

I have added the REACT_APP_SERVER_URL env key in the web.config file and the React App is hosted on the IIS manager. I did a console.log(process.env.REACT_APP_SERVER_URL) in React to read the value of this key but I always get back the value of undefined.

I have also hosted a Node Express server on the same IIS manager instance and the environment variables works fine there. I am not sure if this is a React issue or IIS manager issue, can someone assist me? Thanks.

calvert
  • 631
  • 10
  • 33
  • 1
    React doesn't read environment variables at runtime, only at build time. See https://create-react-app.dev/docs/adding-custom-environment-variables – Phil Aug 16 '22 at 23:55
  • 1
    Does this answer your question? [Reading environment variable in run time after running npm build for a create-react-app based project](https://stackoverflow.com/questions/51401640/reading-environment-variable-in-run-time-after-running-npm-build-for-a-create-re) – Phil Aug 17 '22 at 00:05
  • Thanks, I was able to resolve it after reading the docs and the forum. Silly me. – calvert Aug 17 '22 at 00:18

0 Answers0