fix: load .env before config (proposal) #50
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR proposes a change to how the
.env
file is loaded.The Problem
At the moment the
.env
file is loaded after the config. However, node-config relies on the env varNODE_CONFIG_ENV
to determine what config to load..env
being loaded after the config, means you need to manually defineNODE_CONFIG_ENV
before runningnpm run dev
. This defeats the purpose of having a.env
file, which is why I propose this change.The Fix
By loading .env before the config, we get rid of the requirement to define the
NODE_CONFIG_ENV
manually before running the application.In fact, this PR follows the officially suggested best practice by dotenv and loads
.env
as early as possible, thereby removing the need of any environment variable to be defined manually prior to application start.Test Results
As far I could test it, this works. However, I think it is a good idea to test it specifically against the official staging setup to make sure things like db access and 3rd-party APIs in fact work.
Additional Information
Changelog is missing because this is just a proposal for now and having the check fail prevents merging this PR with a wrong date in the changelog.
Discord Username
examplewastaken