5

I have a react app hosted on a node docker container. I run it and pass it an environment variable

 docker run -t -e "ADMIN_HOST_ENV=http://myapp.app:443/api" -p 3000:3000 "myapp"

How can I get that "ADMIN_HOST_ENV" environment variable within the app?

criver.to
  • 520
  • 2
  • 9
  • 18
  • 1
    Possible duplicate of [Read environment variables in Node.js](http://stackoverflow.com/questions/4870328/read-environment-variables-in-node-js) – Matt Jan 26 '17 at 23:06

1 Answers1

4

If this is just about the node backend, there's already a question with a answer: Read environment variables in Node.js

On the frontend, you'll have several options to get at it, create an endpoint to get it, write it to a .js file that's referenced by the frontend, pass it up as a cookie, keep it backend side and only reference it when you hit the backend, etc.

I check environment variables when I run my server, write them to an environment.js, and then reference that environment.js in my index.html.

Community
  • 1
  • 1
SethWhite
  • 1,891
  • 18
  • 24