-
Notifications
You must be signed in to change notification settings - Fork 44
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
Optional use of another .env file as .env.defaults for shared variables #151
Comments
hmmm that's a decent feature request! Instead of using that package we could supply an array of strings to load. for env files and call What would you suggest the outcome be if you have an env define in both files? |
Happy you like the idea.
Fortunately, 1 and 2 is the current strategy of the original dotenv package, check it here If you agree in that order then you can do it as the other package is doing it (merging the variables from the main file at last) const merge = (main = {}, defaults = {}) => Object.assign({}, defaults, main) So, what do you think? ;) |
Realistically envs should be envs in production ;) so reading from .env on the server and having a hierarchy seems a little too much in terms of a production env. Ideally I'd like to encourage people not to create an .env file in production and not to depend on files to contain envs in production also. Dev yea why not, might be handy but I can see that if we allow this feature, someone will end up depending on files in a production environment which is a bit meh. Perhaps we should throw an exception? For duplicated env declaration because that's not going to happen in prod. But then we're depending on dotenv to load our envs. tough one 😂 |
Thanks for a nice exchange, and sorry for my long answer 😞 As I said it's quite opinionated the way developers handle environments, I put those priorities cause in my experience that's how most of the teams configure them. Let's try to cover most of the scenarios (I said try, cause everyone has their own ways 🤓 )
And answering your ideas
I can understand your approach, as I said, it's quite opinionated how developers handle this topic.
Totally agree with you. Unfortunately you can propose and encourage this approach, but in the end you cannot force a developer to not take the wrong path, it's up to them
That could be an option, but makes it a bit over-engineering. However, validation of the environment variables is also a nice one. If you want to see a weird all-in-one strategy check this package for webpack, which by convention/configuration deals with a (.env.example) for validation and (.env.defaults) for defaults variables. A bit of dark magic but in the end, some developers find it useful. |
Thumbs up, would be cool to have this feature! |
haven't forgotten, just been incredibly busy with work :( |
Hi, just came here while looking for a way to have .env.defaults in our project and it looks like this is quite an old discussion. Did it come to any conclusions? |
Issue type:
nestjs-config version
1.4.3
@nestjs/common+core or other package versions
Excepted behavior
First of all, Excellent Job! Thanks!
There are some scenarios where environment variables, which are not dependent on any environment, would/could/must be shared or included in your building process.
(e.g.) default email address for contact information, single OAUTH server for authentication, etc.
There is a package dotenv-defaults which provides this kind of functionality (it's just an extension of the original dotenv, but reads another file, like .env.defaults, and merge the values)
Would be a smaller but a nice enhancement of the functionality that your library already provides
Actual behavior or outcome (for issue)
Currently, this package supports a single parsing of a ".env" file
The text was updated successfully, but these errors were encountered: