Complete set of utils manage environment variables in Deno applications.
- Set, Get, Check and Delete: Simple functions to handle all your variables.
- Intuitive and fully documented API: Handle single or multiple variables with ease.
- Custom environment filename: Supports loading .env file with custom naming.
- Auto loading variables: If preferred, use one line to load your .env file.
- Fully tested: 100% code and branch coverage using Deno test utils.
deno add @guille/env
Auto load the .env file or manually load with custom filename:
import 'jsr:@guille/env/load';
// === OR ===
import { initEnv } from 'jsr:@guille/env';
await initEnv('.env.local');
Get single or multiple variables at once:
import { getEnv } from 'jsr:@guille/env';
const host = getEnv('DB_HOST'); // '127.0.0.1'
const [host, port] = getEnv('DB_HOST', 'DB_HOST'); // ['127.0.0.1', '5432']
Check existence of single or multiple variables:
import { hasEnv } from 'jsr:@guille/env';
if (hasEnv('FEATURE_ENABLED')) {
// Do things....
}
const [driver, port] = hasEnv('MAIL_DRIVER', 'WRONG'); // [true, false]
Check if all variables exists, useful to validate feature access:
import { hasEnvAll } from 'jsr:@guille/env';
if (hasEnvAll('MAIL_DRIVER', 'MAIL_PORT', 'MAIL_USER')) {
// Proceed to send emails....
}
Manually set variables at runtime:
import { setEnv } from 'jsr:@guille/env';
setEnv('QUEUE_AMOUNT', '35');
const queueAmount = getEnv('QUEUE_AMOUNT'); // '35'
Delete single or multiple variables from environment:
import { delEnv } from 'jsr:@guille/env';
delEnv('DB_HOST');
const host = getEnv('DB_HOST'); // undefined
Any question of issue found? Please rise it on the Issues page.
Thanks for considering contributing to this project! Please make a Pull Request to see your contribution added!
This project is licensed under the MIT license.