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

Support for Multiple .env Files #638

Closed
KhudaDad414 opened this issue Dec 11, 2023 · 4 comments · Fixed by #683
Closed

Support for Multiple .env Files #638

KhudaDad414 opened this issue Dec 11, 2023 · 4 comments · Fixed by #683
Labels
enhancement New feature or request released

Comments

@KhudaDad414
Copy link
Member

Reason/Context:
Currently, Glee only supports parsing environment variables from the .env file. However, the capability to parse additional environment configurations from files like .env.local is missing. This feature is essential for handling different environments more effectively, such as development and production.

Proposed Solution:
To enhance Glee's environment parsing capabilities, I propose we integrate the @next/env package. This package efficiently manages multiple .env files, automatically loading appropriate environment settings based on the application's context. This integration will streamline Glee's configuration process and align it with common development practices.

@KhudaDad414 KhudaDad414 added the enhancement New feature or request label Dec 11, 2023
@AkhilJ321
Copy link
Contributor

@KhudaDad414. So here we are looking for a functionality , where we have multiple envs like .env.production .env.development and then according to NODE_ENV specific env is used.SO we can acheive this thing by require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` });.

@AkhilJ321
Copy link
Contributor

@KhudaDad414 ,I made the changes in code, but i am confused about how to test this thing out in my local setup.

@KhudaDad414
Copy link
Member Author

@AkhilJ321, I suggest you follow the following steps:

  1. Install @next/env.

  2. Use the loadEnvConfig function to load the configuration in the index.ts file of Glee. It should be something like loadEnvConfig(GLEE_PROJECT_DIR, isDev). You can check if it is a development environment by verifying whether process.env.NODE_ENV is set to development or production.

  3. Document how Glee can now support multiple .env files. You can draw inspiration from Next.js environment variables documentation since Glee will use Next.js's package, and the functionality will be the same.

  4. For testing, run one of the examples and then create files like .env, .env.local, .env.production, .env.development, adding environment variables to them. Afterwards, log these variables in the example's function to see if it picks up the variables as expected.

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 0.35.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
3 participants