Skip to content

Commit

Permalink
Allow setting NODE_ENV via env in JSON configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Mar 5, 2024
1 parent 839c912 commit 95e8d60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.`)
Expand Down

0 comments on commit 95e8d60

Please sign in to comment.