Skip to content

wunderflats/configman

Repository files navigation

configman

Tool for defining and checking environment variables in one place.

npm install @wunderflats/configman

Usage

const envVars = ["PORT", "HOSTNAME"];

const configman = require("@wunderflats/configman").ensureAllSet(envVars);

http.createServer().listen(configman.get("PORT"), configman.get("HOSTNAME"));

API

require('@wunderflats/configman')

const configman = require("@wunderflats/configman");

Returns an object of type Configman:

type Configman = {
  ensureAllSet(environmentVariables: string[]): Configman,
  get(environmentVariable: string): string
}

ensureAllSet()

configman.ensureAllSet(environmentVariables: string[]) : Configman

Checks if all environment variable are set and throws if not. Returns configman.

process.env.PORT = 1337;
process.env.YAWP = undefined;

configman.ensureAllSet(["PORT"]);

console.log(configman.get("PORT")); // { PORT: 1337}

config = configman.ensureAllSet(["YAWP"]); // throws since `YAWP` is not set (part of `process.env`)

get()

configman.get(environmentVariable: string): string

Returns an object containing properties for all configured environment variables.

Throws if one of those variables is not set (part of process.env) when accessed.

process.env.PORT = 1337;
process.env.YAWP = undefined;

const PORT = configman.get("PORT");

console.log(PORT); // 1337

const YAWP = configman.get("YAWP"); // throws since `YAWP` is not set (part of `process.env`)

About

Tool for defining and checking environment variables in one place.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •