Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.env subfolders #8

Closed
raychz opened this issue Feb 25, 2019 · 3 comments
Closed

.env subfolders #8

raychz opened this issue Feb 25, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@raychz
Copy link

raychz commented Feb 25, 2019

In my project's root, I have a .env folder where I store my .env.<environment> and .env.<environment>.local files. This works great when I pass the { cwd: '.env/' } option to config, but I'd like to have subfolders under .env that would hold each pair of environment files.

For example:

.env/
-----.env
-----.env.local
-----development/
----------.env.development
----------.env.development.local
-----staging/
----------.env.staging
----------.env.staging.local
-----production/
----------.env.production
----------.env.production.local

Changing the cwd option to .env/* or .env/**/* doesn't seem to work and my project fails to recognize variables not in .env or .env.local. Any ideas?

@kerimdzhanov
Copy link
Owner

I think it's possible to implement this feature to work using the path template. It would look like:

require('dotenv-flow').config({
  path: './.env/${NODE_ENV}/.env.${NODE_ENV}?(.local)'
});

The same approach applies to #7. For that example, it would look like:

require('dotenv-flow').config({
  path: './?(local.)${NODE_ENV}.env'
});

As you can understand this is not supported by the module at the time, so your PR's are very welcome!

@kerimdzhanov kerimdzhanov added the enhancement New feature or request label Feb 26, 2019
@MrSlimCoder
Copy link

Can i send PR on this issue i'm currently understanding the codebase after that i will send PR .

@kerimdzhanov
Copy link
Owner

Hello gentlemen,

With the new pattern option this particular case will become as easy as:

require('dotenv-flow').config({
  pattern: '.env/[node_env/].env[.node_env][.local]'
});

This feature is going to be released with dotenv-flow v4.x.

kerimdzhanov added a commit that referenced this issue Aug 31, 2023
…s' naming convention, closes #8

This PR introduces a new configuration option `pattern`. It allows users to define a custom naming convention for `.env*` files that dotenv-flow will read.

The default value for the `pattern` option is `".env[.node_env][.local]"` which is fully backward-compatible with the current dotenv-flow's naming convention.

BREAKING CHANGE: `.listFiles()` (exposed internal API method) doesn't receive argument `dirname` anymore and returns a list of filenames without the full path (just a name of the file).
kerimdzhanov added a commit that referenced this issue Aug 31, 2023
…s' naming convention, closes #8

This PR introduces a new configuration option `pattern`. It allows users to define a custom naming convention for `.env*` files that dotenv-flow will read.

The default value for the `pattern` option is `".env[.node_env][.local]"` which is fully backward-compatible with the current dotenv-flow's naming convention.

BREAKING CHANGE: `.listFiles()` (exposed internal API method) doesn't receive argument `dirname` anymore and returns a list of filenames without the full path (just a name of the file).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants