Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 1.5 KB

readme.md

File metadata and controls

76 lines (50 loc) · 1.5 KB

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`)