0.2.0 • Published 1 year ago

@tnezdev/env v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@tnezdev/env

A wrapper to make dealing with environment variables less painful.

Installation

  • npm: npm install @tnezdev/env
  • yarn: yarn add @tnezdev/env
  • pnpm: pnpm add @tnezdev/env

Usage

Require this in any file where you need to reference an environment variable. It will throw if the expected key is not defined, otherwise it will return a string.

import { getEnv } from "@tnezdev/env";
import SomeClient from "./clients/some-client";

const configureDefaultClient = () =>
  new SomeClient({
    username: getEnv("SOME_CLIENT_USERNAME"),
    password: getEnv("SOME_CLIENT_PASSWORD"),
  });

export default function (client = configureDefaultClient()) {
  // ... do something cool ...
}

You can also provide a default value to use if the key is not defined in process.env:

getEnv("BASE_URL", { default: "http://localhost:3000" });
0.2.0

1 year ago

0.1.0

1 year ago

0.0.1

1 year ago