feat: load config file depending on `NODE_ENV`
willow hai@wlo.moe
Wed, 28 May 2025 17:54:41 +0100
3 files changed,
14 insertions(+),
5 deletions(-)
M
.gitignore
→
.gitignore
@@ -1,5 +1,6 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore -.config.json +.config.*json +!.config.example.json # Logs
M
README.md
→
README.md
@@ -7,7 +7,7 @@
### requirements - bun - get it here https://bun.sh/ + - get it here https://bun.sh/ - a mongodb database - get it here https://www.mongodb.com/try/download/community@@ -27,8 +27,12 @@ cd stealth-developers
bun install ``` -configure variables in `.config.json`, copy `.config.example.json` to -`.config.json` and fill in the values. +configure variables in `.config.{ENVIRONMENT}.json`, copy `.config.example.json` +to `.config.json` and fill in the values. + +`ENVIRONMENT` is defined by the `NODE_ENV` environment variable; if not set, it +will default to `DEV`. + ### running
M
src/config.ts
→
src/config.ts
@@ -28,7 +28,11 @@ trelloBoardId: z.string().optional(),
}); function validateConfig() { - const runtimeConfig = JSON.parse(fs.readFileSync(".config.json", "utf8")); + const env = process.env.NODE_ENV || "DEV"; + + const runtimeConfig = JSON.parse( + fs.readFileSync(`.config.${env}.json`, "utf8"), + ); const conf = schema.safeParse(runtimeConfig); if (conf.success) return conf.data;