Fastify plugin to check environment variables
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Fix test error message Sep 23, 2018
.gitignore [FEATURE] support dotenv library [resolves #27] May 12, 2018
.travis.yml Add nodejs 10 Apr 29, 2018
LICENSE Initial commit Sep 14, 2017
README.md docs: fix typo (#38) Sep 19, 2018
index.js remove xtend Oct 28, 2018
package.json fix(package): update dotenv to version 6.2.0 (#45) Dec 8, 2018

README.md

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, default: 'config'
  schema: schema,
  data: data // optional, default: process.env
}

fastify
  .register(fastifyEnv, options)
  .ready((err) => {
    if (err) console.error(err)

    console.log(fastify.config) // or fastify[options.confKey]
    // 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