Environment variable validation using dotenv and nope-validator
npm install nope-env> Environment variable validation using dotenv & nope-validator
- About
- Install
- Usage
- Contribute
- License
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.
This project uses node and npm.
``sh`
$ npm install nope-env
$ # OR
$ yarn add nope-env
Given we want the following environment variables to exist:
`bash`
PROJECT_ENV=devNOTE: 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
`js
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.
1. Fork it and create your feature branch: git checkout -b my-new-featuregit commit -am "Add some feature"
2. Commit your changes: git push origin my-new-feature`
3. Push to the branch:
4. Submit a pull request
MIT