Yoctol/bottender

multiple envs handle with .env.dev .env.prod etc

dcsan opened this issue · 1 comments

dcsan commented

Is your feature request related to a problem? Please describe.
I have a local development and production version of the bot.
typically I would use different .env files eg
.env.development and .env.production
and based on NODE_ENV pick these up.

however since bottender is handling this, I'm not sure how I can intercept earlier to setup my ENV
or if you will load by default the .env file only.

There is also this package that handles this a bit transparently, although it is a bit "magical" and should be documented if you use that.

https://www.npmjs.com/package/dotenv-flow

Describe the solution you'd like
A way to not have to keep switching the .env files...

Describe alternatives you've considered
trying to load this before bottender setup. but this seems risky, two different packages loading up process.env
https://www.npmjs.com/package/dotenv-flow

Additional context

dcsan commented

actually I just added this at the top of my server.js and it seems to work

// do this first!
require('dotenv-flow').config();

even if you reload the default .env due to dotenv behavior

https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set

already set env vars won't get overwritten.
I also make sure to remove any plain .env
still seems a bit risky but works for me.