kerimdzhanov / dotenv-flow

Loads environment variables from .env.[development|test|production][.local] files for Node.js® projects.
MIT License
859 stars 36 forks source link

Ability to change `NODE_ENV` option to switch .env.<NODE_ENV> files #44

Closed dmi3y closed 3 years ago

dmi3y commented 3 years ago

I'm using NextJs with dotenv-flow and using non standard environments as staging and edge.

When trying to load my .env.staging or .env.edge set of env variables with NODE_ENV=staging|edge next dev it does "normalize" NODE_ENV variable to be development instead, and giving following warning: image see additional explanation here

It would be nice to have ability to provide alternative option so dotenv-flow can be used with it e.g. APP_ENV=staging next dev

If this sounds as a good idea I'll be happy to work on it.

kerimdzhanov commented 3 years ago

Hi Dmitry,

Sorry for the late reply.

dotenv-flow actually doesn't rely on process.env.NODE_ENV, it just uses it as a default value for options.node_env if you don't provide it explicitly.

So if you want to use i.e. APP_ENV environment variable instead of NODE_ENV, you can do it like this:

require('dotenv-flow').config({
  node_env: process.env.APP_ENV || 'development'
});
dmi3y commented 3 years ago

Hi Dmitry,

Sorry for the late reply.

dotenv-flow actually doesn't rely on process.env.NODE_ENV, it just uses it as a default value for options.node_env if you don't provide it explicitly.

So if you want to use i.e. APP_ENV environment variable instead of NODE_ENV, you can do it like this:

require('dotenv-flow').config({
  node_env: process.env.APP_ENV || 'development'
});

Perfect! Thanks!