Zero-dependency .env to javascript object parser
npm install parse-dotenv --save
# .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
import parseEnv from "parse-dotenv";
const parsed = parseEnv();
console.log(parsed.DB_CONNECTION); // mysql
or provide a path (relative to project root) to env
const parseEnv = require("parse-dotenv");
const parsed = parseEnv(".env.example");
console.log(parsed.DB_PORT); // 3306
Type: string
Default: path.resolve(process.cwd(), '.env')
Type: Object
Type: boolean
Default: false
Parse empty lines in env file
{
emptyLines: true; // parse empty lines in env
}
Type: boolean
Default: false
Parse empty lines in env file
{
comments: true; // parse comments in env
}
- sync-dotenv - Keep your .env in sync with .env.example
This project is licensed under MIT