envobj
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

Envobj

NPM version NPM downloads Build status Test coverage

Tiny environment variable helper.

Ensures that all the required variables are present. Throws on invalid and missing values.

Install

npm install envobj

Usage

const { envobj, string, number, boolean } = require("envobj");
 
const env = envobj(
  {
    DATABASE_URL: string,
    PORT: number,
    USE_PAPERTRAIL: boolean
  },
  process.env,
  {
    PORT: "8000" // Requires a number, set `8000` if `PORT` is missing.
  }
);

Built-in validators: string, number, boolean and integer.

.env

Use with localenv to populate process.env automatically in development from .env and .env.local.

import { envobj, number } from "envobj";
 
import "localenv";
 
export const env = envobj(
  {
    PORT: number
  },
  process.env
);

Tip: Check in .env and exclude .env.local so teammates can get started quickly.

License

MIT

/envobj/

    Package Sidebar

    Install

    npm i envobj

    Weekly Downloads

    344

    Version

    2.0.2

    License

    MIT

    Unpacked Size

    19.3 kB

    Total Files

    8

    Last publish

    Collaborators

    • blakeembrey
    • mattmueller