https://github.com/ericc-ch/env
(very) simple wrapper around std-env
https://github.com/ericc-ch/env
utilities
Last synced: about 1 year ago
JSON representation
(very) simple wrapper around std-env
- Host: GitHub
- URL: https://github.com/ericc-ch/env
- Owner: ericc-ch
- License: mit
- Created: 2024-08-31T01:28:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-10T13:53:13.000Z (over 1 year ago)
- Last Synced: 2025-04-07T05:18:35.289Z (about 1 year ago)
- Topics: utilities
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@echristian/env
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @ericc/env
> A simple wrapper around std-env, providing a convenient interface for environment variable handling.
## Installation
```bash
npm i @echristian/env std-env
```
## Dependencies
This package requires `std-env` as a peer dependency. Make sure to install it alongside this package:
- `std-env` >= 3.0.0
## Why?
This package provides a simplified interface for common environment variable operations:
1. Throw when required environment variable does not exist
2. Fallback to default value for optional variable
3. Avoid repeatedly writing optional chaining and error throwing (with this the value won't be `Value | undefined`)
## Usage
```typescript
import { getEnv } from "@ericc/env";
import { env } from "std-env";
// Using getEnv helper
const API_KEY = getEnv("API_KEY"); // throws if not found
const IMAGE_DIR = getEnv("IMAGE_DIR", "/tmp"); // with fallback
// Use std-env directly for its exports
console.log(env.NODE_ENV);
console.log(env.platform);
```
## Related
Check out [std-env](https://github.com/unjs/std-env) because [unjs](https://github.com/unjs) is awesome.