envbank
v1.0.1
Published
Lightweight, zero-dependency .env parser and loader for Node.js
Maintainers
Readme
envbank
A lightweight, zero-dependency environment variable manager for Node.js. Parse .env strings or load .env files straight into process.env.
Install
npm install envbankUsage
parse(src)
Parse a .env string into an object. Handles KEY=value assignments, strips single/double quotes, trims whitespace, and ignores # comments.
const { parse } = require('envbank');
const env = parse(`
# server config
PORT=3000
NAME="my app"
GREETING='hello world'
`);
console.log(env.PORT); // '3000'
console.log(env.NAME); // 'my app'config(options)
Read a .env file, parse it, and inject the variables into process.env.
const { config } = require('envbank');
// loads ./.env (utf8), existing variables are NOT overwritten
config();
// custom options
config({
path: 'config/secrets.env', // file path (default: '.env')
encoding: 'utf8', // file encoding (default: 'utf8')
override: true // overwrite existing process.env vars (default: false)
});Returns { parsed } with the parsed key/value object.
API
| Method | Description |
| ---------------- | -------------------------------------------------------- |
| parse(src) | Parse an env string into an object. |
| config(options)| Load a .env file into process.env. |
Options
| Option | Type | Default | Description |
| ---------- | -------- | -------- | ------------------------------------ |
| path | string | .env | Path to the env file. |
| encoding | string | utf8 | File encoding. |
| override | boolean| false | Overwrite existing process.env values. |
Test
npm testLicense
MIT
