Zentral is a TypeScript-first module that combines the convenience of environment variables with the confidence of file based configs.
Never worry about missing environment variables or accidental typos in process.env[...]
calls ever again.
# install locally (recommended)
npm install zentral --save
Create a config file somewhere in your project that contains the desired schema:
// src/config.ts
import zentral from "zentral";
const config = zentral.config({
hello: {
type: "string",
default: "my-default"
},
world: {
nested: {
type: "number"
}
}
});
export default config;
That's it! Now you can import your src/config.ts
module anywhere in your code and access all config properties with full autocompletion.
All schema properties get converted to the corresponding environment variables (hello
=> HELLO
, world.nested
=> WORLD_NESTED
).
If the environment variable exists, it gets parsed to the defined type, but if it doesn't the default value is chosen.
If the default value is also missing (or the parsing fails) an error is thrown.