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

dotenv-tiny

v0.2.1

Published

Tiny .env parser. Multi-line quoted values, escapes, comments, export prefix, optional ${VAR} expansion. Zero dependencies.

Readme

dotenv-tiny

ci

npm downloads bundle

Tiny .env parser. Multi-line quoted values, escape sequences, comments, export prefix, optional ${VAR} expansion. Zero dependencies, no fs access (pure function — you bring the text).

import { parse, apply } from "dotenv-tiny";
import { readFileSync } from "node:fs";

const parsed = parse(readFileSync(".env", "utf8"), { expand: true });

apply(parsed);                       // writes into process.env (preserves existing)
apply(parsed, target, { override: true });

Install

npm install dotenv-tiny

Works with Node 20+, browsers, Bun, Deno. ESM + CJS.

Why

The classic dotenv package is fine but:

  • CJS-first, awkward in modern ESM projects
  • Reads files for you — you can't use it in edge runtimes that don't have fs
  • Confusing options surface (override, preload, processEnv, ...)

dotenv-tiny is a pure parser. You read the file yourself (in any way that makes sense for your runtime), pass the text in, get a flat key/value object back. Optionally call apply() to push into process.env.

Edge runtime? parse(env_string_from_kv_store). Vite? Pass the result through define. Test? Use the object directly without touching env.

What's supported

# Comments on their own line
PLAIN=hello
QUOTED="hello world"
ESCAPED="multi\nline\tvalue"
SINGLE='${LITERAL}'           # single quotes: no escapes, no expansion
BACKTICK=`also literal`

MULTILINE="
  line 1
  line 2
"

export EXPORTED=1             # `export` prefix is accepted (and ignored)

WITH_COMMENT=value # inline comment

EXPANDED=${PLAIN}/x           # only with parse(text, { expand: true })

Recipes

Load .env file in Node

import { parse, apply } from "dotenv-tiny";
import { readFileSync } from "node:fs";

const parsed = parse(readFileSync(".env", "utf8"), {
  expand: true,
  expandSource: process.env,
});
apply(parsed);

Load from a Cloudflare Workers KV

import { parse, apply } from "dotenv-tiny";

export default {
  async fetch(req: Request, env: Env) {
    const envText = await env.CONFIG_KV.get("env-config");
    if (!envText) return new Response("missing config", { status: 500 });

    const parsed = parse(envText);
    // Merge into a config object instead of process.env (which doesn't exist on Workers)
    const config = { ...defaultConfig, ...parsed };
    return handle(req, config);
  },
};

Pattern: load + validate

import { parse } from "dotenv-tiny";
import { v } from "@p-vbordei/tiny-validator";
import { readFileSync } from "node:fs";

const Env = v.object({
  PORT: v.string().pattern(/^\d+$/).transform(Number),
  DATABASE_URL: v.string().min(1),
  DEBUG: v.string().optional(),
});

const raw = parse(readFileSync(".env", "utf8"), { expand: true });
const config = Env.parse(raw);
// config is typed: { PORT: number; DATABASE_URL: string; DEBUG?: string }

Layered config (.env, .env.local, .env.production)

import { parse, apply } from "dotenv-tiny";
import { readFileSync, existsSync } from "node:fs";

function loadIfExists(path: string, opts?: any) {
  if (!existsSync(path)) return {};
  return parse(readFileSync(path, "utf8"), opts);
}

const merged = {
  ...loadIfExists(".env"),
  ...loadIfExists(`.env.${process.env.NODE_ENV}`),
  ...loadIfExists(".env.local"),  // last wins
};
apply(merged, process.env, { override: true });

Inline expansion without touching process.env

import { parse } from "dotenv-tiny";

const config = parse(`
  HOME_DIR=/home/vlad
  CONFIG_PATH=\${HOME_DIR}/.config
`, { expand: true });
// config.CONFIG_PATH === "/home/vlad/.config"

API

parse(text, opts?): Record<string, string>

Pure function. Returns a flat object. Never throws.

| Option | Type | Meaning | |---|---|---| | expand | boolean | Substitute ${VAR} / $VAR in unquoted and double-quoted values | | expandSource | Record<string, string \| undefined> | Fallback source for expansion (e.g. process.env) |

Single-quoted and backtick-quoted values are never expanded.

apply(parsed, target?, opts?): { applied: string[]; skipped: string[] }

Write parsed values into a target object. Defaults: target is process.env, override: false (existing keys preserved).

Caveats

  • No file watching. Read the file when your app starts; if you need live reload, watch and re-parse yourself.
  • No .env.local etc. conventions — bring your own layering (see Recipes).
  • String values only. All values are strings. Coerce types yourself (or use tiny-validator.transform).

License

Apache-2.0 © Vlad Bordei