aks-env-loader
v1.0.4
Published
A simple environment loader and validator for Node.js written in TypeScript.
Maintainers
Readme
🟢 aks-env
A simple, dependency-free environment loader and validator for Node.js (TypeScript + ESM).
✨ Features
Load environment variables from
.envValidate required variables
Access strongly typed values (
string,number,boolean)Defaults supported
Zero dependencies
📦 Installation
npm install aks-env
🚀 Usage
1. Create a .env file
Copy code
PORT=4000
DB_URL=mongodb://localhost/db
DEBUG=true
2. Use it in your project
Copy code
import { loadEnv, validateEnv, getValue } from "aks-env";
loadEnv(".env");
validateEnv(["PORT", "DB_URL"]);
const port = getValue("PORT", "number");
const db = getValue("DB_URL");
const debug = getValue("DEBUG", "boolean", false);
console.log({ port, db, debug });
🛡 Validation
If a required variable is missing:
Copy code
validateEnv(["API_KEY"]);
Throws:
Copy code
Missing required environment variables: API_KEY
🔧 Typed Access
Copy code
const port = getValue("PORT", "number", 3000);
const debug = getValue("DEBUG", "boolean");
const mode = getValue("MODE", "string", "development");
📜 License
MIT License
