env-vars-validator
A library who will validate your environment variables from AJV schema.
Usage
const { validateEnv } = require("env-vars-validator")
validateEnv(
{
NODE_ENV: { type: 'string' },
PORT: { type: 'integer' },
},
{
requiredProperties: ['NODE_ENV'],
},
);
API
validateEnv(schema, options?)
Return: void
Able to validate env var from Ajv Properties Fields.
Options
Field Name | Type | Default | Description |
---|
requiredProperties | string[] | [] | Indicate if field is required (More Information : JSON Schema Required) |
coercevars | boolean | true | Indicate if fields will be cast to type (Example: NODE_ENV will be cast to number in our usage example) |
currentEnv()
Default: development
Return: Boolean
Return current NODE_ENV without space and in lowercase format
isProductionEnv()
Return: Boolean
Return if NODE_ENV is equal to production
isDevelopmentEnv()
Return: Boolean
Return if NODE_ENV is equal to development
isTestEnv()
Return: Boolean
Return if NODE_ENV is equal to test
isDeployedEnv()
Return: Boolean
Return if NODE_ENV is not equal to development
and to test
Maintain
This package use TSdx. Please check documentation to update this package.