Reputation: 17332
I'm using this Dockerfile:
FROM node:8.4.0
COPY . /
ENV MONGO_URL=mongodb://mongo-container/data
ENV PORT=80
EXPOSE 80
CMD node /index.js
In the index.js file I want to check for the ENV variables. As the docker image is used in productive, I would run the app with development environment if the ENV variable is not set. Something similar to this:
index.js
const mongoUrl = ENV.MONGO_URL || 'mongodb://localhost:3001'
Running the Docker image should use the productive mongoDB, running locally should use localhost DB
Upvotes: 0
Views: 5477
Reputation: 51768
process.env object contains all the user environment variables. Check link for more info https://nodejs.org/api/process.html#process_process_env
Upvotes: 2