env-vars-validator
TypeScript icon, indicating that this package has built-in type declarations

1.2.56 • Public • Published

Maintainability Test Coverage npm npm Snyk Vulnerabilities for npm package NPM

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

isPreproductionEnv()

Return: Boolean

Return if NODE_ENV is equal to preproduction

isStagingEnv()

Return: Boolean

Return if NODE_ENV is equal to staging

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.

Readme

Keywords

none

Package Sidebar

Install

npm i env-vars-validator

Weekly Downloads

382

Version

1.2.56

License

MIT

Unpacked Size

28.9 kB

Total Files

12

Last publish

Collaborators

  • qlaffont