nope-env
Environment variable validation using dotenv & nope-validator
Table of Contents
About
This package is a small wrapper around dotenv & nope-validator which allows you to validate your environment variables based on a schema. It also includes dotenv-expand for variable expansion.
Install
This project uses node and npm.
$ npm install nope-env
$ # OR
$ yarn add nope-env
Usage
Given we want the following environment variables to exist:
PROJECT_ENV=dev
# NOTE: We are using the ${} syntax from dotenv-expand here
NEXT_PUBLIC_API_URL=https://${PROJECT_ENV}.api.example.com
NEXT_PUBLIC_SENTRY_DSN=https://sentrydsn.com
ADMIN_EMAIL=admin@example.com
The following schema can be provided to config
const env = require('nope-env')
env.config({
// dotenv configuration can go here...
schema: {
// env.string() === Nope.string()
PROJECT_ENV: env.string().oneOf(['dev', 'staging', 'uat']),
NEXT_PUBLIC_API_URL: env.string().required().url(),
NEXT_PUBLIC_SENTRY_DSN: env.string().url(),
ADMIN_EMAIL: env.string().email().required()
}
})
This package exposes all of the nope-validator
API. Please see their docs for validation options.
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT