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

@debbl/with-env

v0.0.0

Published

Load .env files the Next.js way, then run any command

Readme

@debbl/with-env

Load .env files the Next.js way, then run any command.

Next.js has the env-file behaviour most people actually want — a .env.local that overrides .env, a mode-specific cascade, $VAR expansion, and real environment variables always winning. It ships that logic as @next/env, but only as an API. This is that API plus a process wrapper, so anything can use it: turbo, vite, wrangler, tsx, a plain node script.

Install

pnpm add -D @debbl/with-env

CLI

with-env turbo run dev
with-env --prod turbo run build
with-env -c ../.. -- vite --port 3000

The first non-option argument starts the command. Everything after it is passed through untouched, so the command keeps its own flags — with-env turbo run dev --filter web gives --filter web to turbo, not to with-env. Use -- when the command itself looks like an option.

| Option | Description | | ----------------- | ----------------------------------------------- | | -c, --cwd <dir> | Directory to load env files from (default: cwd) | | --dev | Force the .env.development* cascade | | --prod | Force the .env.production* cascade | | -q, --quiet | Do not report on stderr which files were loaded | | -h, --help | Show help | | -v, --version | Show the version |

The "loaded ..." line goes to stderr, never stdout, so piping the wrapped command's output stays clean. The command's exit code is passed through, and SIGINT/SIGTERM are forwarded to it.

API

import { loadEnv } from '@debbl/with-env'

const { env, files } = loadEnv({ quiet: true })

loadEnv applies the files to process.env and returns the merged env plus the files it read, in precedence order.

| Option | Default | Description | | ------- | --------------------------- | ---------------------------------------------------- | | cwd | process.cwd() | Directory to look in | | dev | NODE_ENV !== 'production' | Development or production cascade | | quiet | false | Silence @next/env's error output | | force | false | Reload even if this process already loaded env files |

Resolution order

With mode being development or production, earlier files win:

  1. .env.{mode}.local
  2. .env.local
  3. .env.{mode}
  4. .env

Variables already set in the real environment are never overwritten, so FOO=1 with-env ... beats every file.

Caveats

Turborepo filters env vars. Since Turborepo 2.0 envMode defaults to strict, which means tasks only receive the variables declared in turbo.json. Loading files before turbo is necessary but not sufficient — you also need:

{
  "globalEnv": ["MY_SECRET"],
  "globalDependencies": [".env", ".env.local"]
}

globalDependencies makes the env files part of the cache key, so changing a value does not hit a stale cache. eslint-plugin-turbo's no-undeclared-env-vars rule catches the ones you forget.

NODE_ENV=test overrides the cascade. @next/env selects the test mode and skips .env.local entirely whenever NODE_ENV is test, regardless of --dev / --prod.

Env files are loaded once per process. @next/env caches its result and snapshots process.env on the first call. Pass force to reload.

Sandboxed runtimes do not see process.env. Wrapping wrangler dev loads the files into the wrangler process, not into the Worker — Cloudflare populates the Worker's process.env from vars and .dev.vars. Same for any runtime with its own environment.

License

MIT