DEV Community

Discussion on: Using Docker for Node.js in Development and Production

Collapse
 
bmnds profile image
bmnds • Edited

Hi, great article! Thanks for sharing your knowledge with us.

I have a doubt about best practices for handling environment variables.
Reading your Dockerfile, i felt a little strange seeing NODE_ENV=development in builder and start:prod later on. I would expect one environment to be the 'default' and the other one would have to override what is needed. But I didn't see it in here, is the default one 'development' or 'production'?

I understand npm install works based on NODE_ENV variable, so whether development or production, it will work as expected.

Is there a similar solution for npm start? To run the correct command based on NODE_ENV variable?

Collapse
 
2anandkr profile image
anand kumar

you can have your npm scripts like : start:development and start:production
In the Dockerfile, you can use CMD [ "npm", “run”, "start:${NODE_ENV}" ].

Collapse
 
gparra profile image
Gleycer Parra

Hi, I have the same doub, if you have found a solution, please shared it, I would appreciate.