Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.16 KB

README.md

File metadata and controls

48 lines (37 loc) · 1.16 KB

fastify-env

Greenkeeper badge Build Status JavaScript Style Guide

Fastify plugin to check environment variables

Install

npm install --save fastify-env

Usage

const fastify = require('fastify')()
const fastifyEnv = require('fastify-env')

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

const options = {
  confKey: 'config', // optional
  schema: schema,
  data: data // optional, default: process.env
}
fastify.register(fastifyEnv, options, function (err) {
   // or fastify[options.confKey]
  console.log(fastify.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 sponsirized by Mia Platform