[Node.js express Docker] How to define Docker environment variables and load them with node.js
- Because we are a fledgling engineer, I think there are many mistakes, so please understand. Also, if you notice any mistakes, please let us know.
It seems that there are several patterns, but for the time being, keep it simple.
Define environment variables in a file called app.env. (Name is arbitrary)
app.env
SECRET_KEY=himitu
Specify the above file as an environment variable file in docker-compose.yml
docker-compose.yml
env_file: ./app.env
Read the environment variable file on node.js side
const env = process.env //Store the object with the name env.
How to take out
env.SECRET_KEY
that's all.