dasilvacontin / perfect-env

An Error is thrown if an unset environment variable is accessed.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

perfect.env

Build Status Coverage Status

Drop-in replacement for process.env that throws an Error if an unset environment variable is accessed.

const perfect = require('perfect-env')

const { PORT, CONSUMER_KEY, CONSUMER_SECRET, APP_URL } = perfect.env

instead of

const { PORT, CONSUMER_KEY, CONSUMER_SECRET, APP_URL } = process.env

if (PORT == null) throw new Error('\'PORT\' environment variable is not set.')
if (CONSUMER_KEY == null) throw new Error('\'CONSUMER_KEY\' environment variable is not set.')
if (CONSUMER_SECRET == null) throw new Error('\'CONSUMER_SECRET\' environment variable is not set.')
if (APP_URL == null) throw new Error('\'APP_URL\' environment variable is not set.')

Exception example:

Error: 'PORT' environment variable is not set.
    at Object.get (your-project-path/node_modules/perfect-env/index.js:6:15)
    at Object.<anonymous> (your-project-path/index.js:3:9)

License

MIT © David da Silva

About

An Error is thrown if an unset environment variable is accessed.


Languages

Language:JavaScript 100.0%