@redpeacock78/unienv
v0.0.19
Published
Unified environment variable management for Node.js, Deno (Deno Deploy), and Bun.
Downloads
222
Maintainers
Readme
UniEnv
Unified environment variable management for Node.js, Deno (Deno Deploy), and Bun.
Usage
Code
Node.js and Bun
import UniEnv from "@redpeacock78/unienv";
Deno
import UniEnv from "npm:@redpeacock78/unienv";
Example
// Referenced from .env file const getEnv = UniEnv.get("EXAMPLE"); if (getEnv.isNg()) console.error(getEnv.error.message); if (getEnv.isOk()) { if (!getEnv.value) { console.error("EXAMPLE is not set!"); } else { console.log(getEnv.value); } } // Set, reference, and delete environment variables // Set environment variables const setKey = UniEnv.set("KEY", "value"); if (setKey.isNg()) console.error(setKey.error.message); if (setKey.isOk()) console.log("Successfully set environment variables!"); // Reference environment variables const getKey = UniEnv.get("KEY"); if (getKey.isNg()) console.error(getKey.error.message); if (getKey.isOk()) { if (!getKey.value) { console.error("KEY is not set!"); } else { console.log(getKey.value); } } // Delete environment variables const rmKey = UniEnv.delete("KEY"); if (rmKey.isNg()) console.error(rmKey.error.message); if (rmKey.isOk()) console.log("Successfully deleted environment variables!");
Run
Node.js
node index.js
Bun
bun run index.js
Deno
deno run --allow-read --allow-env index.ts
Runtime Version Requirements
|Node.js|Bun|Deno|
|:-:|:-:|:-:|
|✅ 14.0.0
or higher|✅ 1.0
or higher|✅ 1.30.0
or higher|
License
MIT