JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 210522
  • Score
    100M100P100Q159981F
  • License MIT

Validate your env variable using Ajv and dotenv

Package Exports

  • env-schema

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (env-schema) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

env-schema

Greenkeeper badge Build Status JavaScript Style Guide

Utility to check environment variables using JSON schema, Ajv and dotenv.

Install

npm install --save env-schema

Usage

const envSchema = require('env-schema')

const schema = {
  type: 'object',
  required: [ 'PORT' ],
  properties: {
    PORT: {
      type: 'string',
      default: 3000
    }
  }
}

const config = envSchema({
  schema: schema,
  data: data // optional, default: process.env
  dotenv: true // load .env if it's there, default: false
})

console.log(config)
// output: { PORT: 3000 }

It is possible to also use fluent-schema:

const envSchema = require('env-schema')
const S = require('fluent-schema')

const config = envSchema({
  schema: S.object().prop('port', S.string().default('3000').required()),
  data: data // optional, default: process.env
  dotenv: true // load .env if it's there, default: false
})

console.log(config)
// output: { PORT: 3000 }

NB: internally this plugin force to not have additional properties, so the additionalProperties flag is forced to be false

Acknowledgements

Kindly sponsored by Mia Platform and NearForm.

License

MIT