joetjen.net
EN DE
← All libraries
JavaScript

node-cooper-config

Loads an application’s CASC configuration once, at startup, with Cooper, and gives the rest of the program four functions to read it.

Intention

Eager on purpose: the document is read once, before anything else runs, and never lazily, reloaded or watched. A broken configuration stops the program at startup instead of at the first request that touches the bad value, every reader sees the same frozen configuration, and reading is a synchronous lookup. It is the Node counterpart of cooper_config, and reads a document the same way.

Example
import '@joetjen/cooper-config/register';   // loads config/config.casc, once
import { get, require } from '@joetjen/cooper-config';

get('server.port');               // 8080
get('server.timeout');            // 30000 (milliseconds)
require('database.password');     // the revealed DB_PASSWORD
get('database.pool.size', 5);     // 10, or 5 if absent
Install
npm install @joetjen/cooper-config
Node.jsConfiguration