-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(env): ♻️ remove unused environment files and add dotenv conf…
…iguration - Add a new config/index.ts file for loading the environment variables from a .env file. - Add validateEnvironment variables function that validates the required environment variables. - Use validateEnvironment variables to ensure the required env variables are available at runtime. - Update index.ts to utilize the validate environment variables function. - Replace usage of consola library with console.log to output 1 + 2.
- Loading branch information
1 parent
4c9d392
commit 2d2f2f0
Showing
12 changed files
with
71 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
NODE_ENV="production" | ||
# API_URL="" | ||
# Environment variables | ||
NODE_ENV=production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
amannn | ||
contributorsrc | ||
envalid | ||
execa | ||
fbca | ||
gacp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { config } from "dotenv"; | ||
|
||
/** | ||
* Loads environment variables from a .env file. | ||
* | ||
* @function | ||
* @returns {void} | ||
*/ | ||
export const loadEnvironmentVariables = (): void => { | ||
config({ path: `.env.${process.env.NODE_ENV ?? "development"}` }); | ||
}; | ||
|
||
loadEnvironmentVariables(); | ||
|
||
/** | ||
* The environment the application is running in. | ||
*/ | ||
export const NODE_ENV = process.env.NODE_ENV; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { cleanEnv, str } from "envalid"; | ||
|
||
/** | ||
* Validates the environment variables needed for the application to run. | ||
* | ||
* @function | ||
* @returns {void} | ||
*/ | ||
export const validateEnvironmentVariables = (): void => { | ||
cleanEnv(process.env, { | ||
NODE_ENV: str(), | ||
}); | ||
}; | ||
|
||
declare global { | ||
// By default, we do not want any namespace in Start UI [web] as it is more | ||
// error prone and not useful in front end applications. | ||
namespace NodeJS { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, unicorn/prevent-abbreviations | ||
interface ProcessEnv { | ||
NODE_ENV: "development" | "production" | "test"; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { consola } from "consola"; | ||
import { validateEnvironmentVariables } from "./config/validateEnvironment"; | ||
|
||
await import("./env/environment"); | ||
validateEnvironmentVariables(); | ||
|
||
consola.log("add 1 + 2: ", 1 + 2); | ||
// eslint-disable-next-line no-console | ||
console.log("add 1 + 2: ", 1 + 2); |