npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

devkits-env-parser

v1.0.0

Published

Parse .env file content into JavaScript object — zero dependencies

Readme

devkits-env-parser

Parse .env file content into JavaScript object. Zero dependencies, handles comments, quotes, and edge cases.

Install

npm install -g devkits-env-parser

npm version

Usage

CLI

# Parse .env content to JSON
env-parser parse "FOO=bar\nBAZ=qux"
# Output: {"FOO":"bar","BAZ":"qux"}

# Parse with quotes
env-parser parse "DB_HOST=\"localhost\"\nPORT=5432"

# Stringify to .env format
env-parser stringify '{"DB_HOST":"localhost","PORT":"5432"}'
# Output: DB_HOST=localhost\nPORT=5432

# Parse .env file
env-parser file .env

# Quote all values
env-parser stringify '{"MSG":"hello world"}' --quote
# Output: MSG="hello world"

Programmatic API

const { parse, stringify } = require('devkits-env-parser');

// Parse .env content
const config = parse(`
  # Database settings
  DB_HOST=localhost
  DB_PORT=5432
  DB_NAME="my database"  # inline comment
`);
// { DB_HOST: 'localhost', DB_PORT: '5432', DB_NAME: 'my database' }

// Parse with quotes
parse('MESSAGE="hello world"');
// { MESSAGE: 'hello world' }

// Handle escaped quotes
parse('QUOTE="say \\"hello\\""');
// { QUOTE: 'say "hello"' }

// Stringify to .env format
stringify({ DB_HOST: 'localhost', PORT: '5432' });
// 'DB_HOST=localhost\nPORT=5432'

// Add comments
stringify(
  { DB_HOST: 'localhost' },
  { comments: { DB_HOST: 'Database host' } }
);
// 'DB_HOST=localhost # Database host'

// Quote all values
stringify({ MSG: 'hello world' }, { quote: true });
// 'MSG="hello world"'

API

parse(content)

Parse .env file content into object.

| Param | Type | Description | |-------|------|-------------| | content | string | .env file content | | Returns | Object | Parsed key-value pairs |

Features:

  • Skips comments (lines starting with #)
  • Handles inline comments (KEY=value # comment)
  • Removes surrounding quotes
  • Unescapes escaped quotes (\"")
  • Ignores empty lines

stringify(obj, options)

Stringify object into .env format.

| Param | Type | Description | |-------|------|-------------| | obj | Object | Key-value pairs | | options | Object | Options | | options.quote | boolean | Quote all values (default: false) | | options.comments | Object | Add comments to keys | | Returns | string | .env file content |

Use Cases

  • Config loading — Parse .env files in Node.js apps
  • Config validation — Check .env file structure
  • Migration scripts — Convert between config formats
  • CI/CD — Generate .env files from secrets
  • Debugging — Inspect environment configurations

Examples

// Load and parse .env file
const fs = require('fs');
const { parse } = require('devkits-env-parser');

const content = fs.readFileSync('.env', 'utf8');
const config = parse(content);

// Generate .env from template
const { stringify } = require('devkits-env-parser');

const envContent = stringify({
  NODE_ENV: 'production',
  PORT: '3000',
  API_KEY: process.env.API_KEY
}, {
  comments: {
    NODE_ENV: 'Environment',
    PORT: 'Server port'
  }
});

Features

  • Zero dependencies — Pure JavaScript
  • Comment support — # comments and inline comments
  • Quote handling — Single and double quotes
  • Escape sequences — Handles \" and \'
  • CLI + library — Command line and programmatic use
  • Lightweight — ~2KB minified

Related Tools

  • dotenv — Load .env into process.env
  • env-cmd — Run commands with environment variables

See Also

Support

Open Collective: Open Collective - DevKits

Crypto: ETH/USDC 0xDea4a6A20fCB44467e45Ef378972F54B22dC59db

License

MIT — DevKits Team