From 95e8d609e1bd4786aaeb943b7b92f21f3aa71dd6 Mon Sep 17 00:00:00 2001 From: Stefan Peters Date: Tue, 5 Mar 2024 12:26:43 +0100 Subject: [PATCH] Allow setting NODE_ENV via `env` in JSON configuration --- README.md | 1 + config/index.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fb4143..4d6c873 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ All missing keys will be defaulted from `config/config.default.json`: { "verbosity": "warn", "baseUrl": null, + "env": "development", "title": "JSKOS Server", "version": null, "closedWorldAssumption": true, diff --git a/config/index.js b/config/index.js index e4f7588..d945537 100644 --- a/config/index.js +++ b/config/index.js @@ -11,7 +11,7 @@ import { v4 as uuid } from "uuid" // Prepare environment import * as dotenv from "dotenv" dotenv.config() -const env = process.env.NODE_ENV || "development" +const env = process.env.NODE_ENV const configFile = process.env.CONFIG_FILE || "./config.json" function getDirname(url) { @@ -77,6 +77,7 @@ if (!configUser.namespace && env != "test") { } let config = _.defaultsDeep({ env }, configEnv, configUser, configDefault) +config.env = config.env ?? "development" if (![true, false, "log", "warn", "error"].includes(config.verbosity)) { console.warn(`Invalid verbosity value "${config.verbosity}", defaulting to "${configDefault.verbosity}" instead.`)