@ericc/env
A simple wrapper around std-env, re-exporting all its functionality while providing a convenient interface for environment variable handling.
Installation
npm i @echristian/env
deno add jsr:@ericc/env
Why?
This package serves as a wrapper around std-env, re-exporting all of its functionality while also providing a simplified interface for common environment variable operations:
- Throw when required environment variable does not exist
- Fallback to default value for optional variable
- Avoid repeatedly writing optional chaining and error throwing (with this the value won't be
Value | undefined
)
Usage
import { getEnv, env } from "@ericc/env";
const API_KEY = getEnv("API_KEY");
const IMAGE_DIR = getEnv("IMAGE_DIR", "/tmp");
console.log(env.NODE_ENV);
console.log(env.platform);
Related
Check out std-env because unjs is awesome.