Greg Daynes

Full Stack Software Design, Development & Management

Envar Loading

Envars are one of those things that seems to bite new members to a project. Most of the time they’re not documented, typed, and local setups gain invalid values over time. I wanted a way to simplify the process, as well as provide useful information to the developer.

  • Use JSON Schema to parse, validate, and provide defaults for values - link
  • Uses common .env file with newline separated KEY=VALUE entries.
  • TEST_ prefixed values will override un-prefixed values in NODE_ENV=test to avoid having multiple .env.* files.

Repo: gregdaynes/env

# Start node repl with envars
$ node -r ./env-loader.js

# node repl
> console.log(process.env)