envokin
v1.0.4
Published
Envokin is a powerful and intuitive environment variable validation library for Node.js applications. Designed to ensure the integrity and correctness of your environment configurations, Envokin simplifies the process of validating environment variables,
Downloads
5
Maintainers
Readme
Envokin
- Envokin is a powerful and intuitive environment variable validation library for Node.js applications.
- Designed to ensure the integrity and correctness of your environment configurations, Envokin simplifies the process of validating environment variables, making your application more robust and secure.
Usage
Base syntax
const envokin = new Envokin(schema, options)
schema
- An object that specifies the format of required varsoptions
- An (optional) object, which supports the following keys:source
- Can be an object or path to file (.json
,.env
).strict
- Boolean value, default isfalse
If the
source
key is not provided in theoptions
,Envokin
will use the variables fromprocess.env
for validation. If thestrict
flag is set totrue
in theoptions
, aValidationError
will be thrown if a value for a key from the schema is not provided in the environment variables.
Basic Usage
import { Envokin } from 'envokin'
const envokin = new Envokin({
HOST: 'host',
PORT: 'port',
URL: 'url',
EMAIL: 'email',
IP: 'ip',
IP4: 'ip4',
IP6: 'ip6',
STRING: 'string',
NUMBER: 'number',
BOOLEAN: 'boolean',
JSON: 'json',
CUSTOM_VALUE: {
validator: (_: string, value: unknown): boolean => typeof value === 'string',
transformer: (value: unknown): string => String(value).toUpperCase()
}
});
envokin.get('EMAIL'); // -> A string value containing a valid email
envokin.get('PORT'); // -> A number value containing a valid port
envokin.isDev; // true if NODE_ENV === 'dev' | 'develop' | 'development'
envokin.isTest; // true if NODE_ENV === 'test' | 't'
envokin.isProduction; // true if NODE_ENV == 'production' | 'prod'