Tool for defining and checking environment variables in one place.
npm install @wunderflats/configman
const envVars = ["PORT", "HOSTNAME"];
const configman = require("@wunderflats/configman").ensureAllSet(envVars);
http.createServer().listen(configman.get("PORT"), configman.get("HOSTNAME"));
const configman = require("@wunderflats/configman");
Returns an object of type Configman:
type Configman = {
ensureAllSet(environmentVariables: string[]): Configman,
get(environmentVariable: string): string
}
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`)
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`)