nope-env

1.0.0 • Public • Published

nope-env

package version package downloads standard-readme compliant package license make a pull request

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

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT

Package Sidebar

Install

npm i nope-env

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

5.19 kB

Total Files

4

Last publish

Collaborators

  • tiaanduplessis