loony-dotenv
v0.1.2
Published
Simple environment loader that reads .env files and automatically populates process.env for Node.js applications.
Maintainers
Readme
📦 loony-dotenv
A tiny, fast, zero-dependency utility for loading .env files into process.env — clean, simple, and reliable.
🚀 Features
- ⚡ Zero dependencies
- 📁 Loads
.envfiles intoprocess.env - 🧼 Handles quotes and whitespace cleanly
- 🛑 Does not overwrite existing env variables
- 🪶 Lightweight and minimal API
- 🧩 Works with both CommonJS and ESM projects
📥 Installation
npm install loony-dotenvor
yarn add loony-dotenv🔧 Usage
Basic example
import loadEnv from "loony-dotenv";
loadEnv(); // loads "./.env"
// Now you can use:
console.log(process.env.MY_VARIABLE);Custom .env file path
loadEnv("./config/custom.env");🧪 Example .env file
PORT=3000
DB_HOST="localhost"
API_KEY='secret-key'📘 API
loadEnv(envPath?: string): void
| Parameter | Type | Default | Description |
| --------- | -------- | ------- | ----------------------- |
| envPath | string | .env | Path to the .env file |
⚠️ Behavior Notes
- Environment variables already set will not be overwritten.
- Lines beginning with
#or empty lines are ignored. - Quoted values (
"value"or'value') are automatically unwrapped.
🛠 How It Works (Simplified)
- Reads the file synchronously
- Splits the contents line-by-line
- Parses
KEY=VALUEpairs - Cleans quotes and whitespace
- Populates
process.env
Clean, obvious, predictable.
🗂 Project Structure Suggestion
project/
├─ index.mjs
├─ .env
└─ package.json🤝 Contributing
Contributions, issues, and feature requests are welcome! Feel free to open a pull request or issue on GitHub:
👉 https://github.com/loony-js/loony-dotenv
📄 License
ISC © Sankar Boro
