luqmanoop / parse-dotenv

Zero dependency .env to javascript object parser

Home Page:https://www.npmjs.com/package/parse-dotenv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parse-dotenv

Zero-dependency .env to javascript object parser

Travis (.org) Coverage Status

Installation

npm install parse-dotenv --save

Usage

# .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

API

path

Type: string

Default: path.resolve(process.cwd(), '.env')

opts

Type: Object

opts.emptyLines

Type: boolean

Default: false

Parse empty lines in env file

{
  emptyLines: true; // parse empty lines in env
}

opts.comments

Type: boolean

Default: false

Parse empty lines in env file

{
  comments: true; // parse comments in env
}

Related

  • sync-dotenv - Keep your .env in sync with .env.example

LICENSE

This project is licensed under MIT

About

Zero dependency .env to javascript object parser

https://www.npmjs.com/package/parse-dotenv

License:MIT License


Languages

Language:TypeScript 100.0%