cross-env

Cross-platform CLI for setting environment variables in npm scripts without worrying about Windows vs POSIX syntax.

Tool
npm
v10.1.0
6,523 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
47 /100 Fair
Development Activity 0
Maintenance 32
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 88
Code Quality 85
Innovation 55
Learning Curve 90

cross-env solves a specific, annoying cross-platform problem: Windows command prompts choke on NODE_ENV=production node script.js-style variable assignment, and Windows uses %VAR% where POSIX shells use $VAR. Rather than maintaining separate win and posix npm scripts, or wrapping every script in a shell-detection hack, cross-env lets you write a single command that works identically everywhere.

It ships as a tiny CLI (cross-env and cross-env-shell) that parses KEY=value pairs off the front of a command, builds the right environment, and then hands the rest of the command off to cross-spawn for execution — translating $VAR/${VAR} references and PATH-style list delimiters to their Windows equivalents when needed. The maintainers consider the feature set complete: the README explicitly states cross-env is “done” and isn’t accepting new features, only maintenance.

What You Get

  • A single cross-env binary that prefixes any command, parsing leading KEY=value assignments before spawning the real process
  • A cross-env-shell variant that runs the command through a shell, useful when the underlying script itself needs $VAR substitution
  • Automatic $VAR/${VAR} to %VAR% conversion so command bodies work under cmd.exe without rewriting them
  • Bash-style default-value expansion (${VAR:-default}) resolved before the command runs
  • PATH-like list-delimiter translation (: to ;) for whitelisted variables such as PATH and NODE_PATH
  • Correct signal forwarding (SIGTERM/SIGINT/SIGBREAK/SIGHUP) and exit-code propagation from the spawned child process

Common Use Cases

  • Setting NODE_ENV=production (or any other var) in a package.json build/start script that has to run on both CI (Linux) and Windows developer machines
  • Chaining a variable-setting script into a downstream script via cross-env-shell so the child script can still use $VAR syntax
  • Passing multiple environment variables to a single command without per-OS branching logic
  • Normalizing PATH-style variables that use OS-specific list separators inside a script

Under The Hood

Architecture cross-env is intentionally small and linear: src/bin/cross-env.ts and src/bin/cross-env-shell.ts are one-line entry points that call the single exported crossEnv() function in src/index.ts with process.argv. crossEnv() does all the real work in three phases — parseCommand() walks the argument list with a regex (envSetterRegex) to split leading KEY=value assignments from the actual command and its arguments (including careful handling of escaped quotes), getEnvVars() builds the child environment by running each assignment’s value through varValueConvert(), and the resulting command/args/env triple is handed to cross-spawn’s spawn() with stdio: 'inherit'. Platform-specific string rewriting is isolated in two small modules, command.ts (converts $VAR references and normalizes paths for Windows) and variable.ts (converts value-level $VAR references and PATH-style delimiters), both gated by the single isWindows() check in is-windows.ts. Nothing else in the codebase branches on platform, so the Windows/POSIX difference is fully contained to those two files. Tech Stack The project is plain TypeScript (type: module, ES modules only, no CommonJS build) with a single runtime dependency, cross-spawn, used for its more reliable cross-platform child-process spawning versus Node’s built-in child_process.spawn. It builds with zshy (a thin TypeScript-to-dual-output bundler), type-checks with tsc --noEmit, and targets Node.js 20+. Dev tooling is the @epic-web/config shared ESLint/Prettier config, and tests run under Vitest with @vitest/coverage-v8 for coverage and @vitest/ui for interactive runs. Code Quality The src/__tests__/ directory has dedicated unit-test files for every module (index, command, variable, is-windows, plus a focused command-default-values suite for the ${VAR:-default} expansion path) totaling roughly 600 lines of test code against ~250 lines of source — a high test-to-source ratio for a project this size. A separate e2e/ directory runs the built CLI end-to-end via plain Node scripts. CI (.github/workflows/validate.yml) runs the full validate script — build, typecheck, lint, format check, and test — and a second workflow auto-formats on push. Error handling is minimal but intentional (e.g. parseCommand throws a clear Error('Command is required') when no command is given); the small surface area means there’s little room for swallowed errors. What Makes It Unique cross-env doesn’t try to be a general shell-compatibility layer — it solves exactly one problem (environment variable assignment syntax differing between POSIX and Windows shells) and stops there, which is why the maintainers call it feature-complete. Its narrow scope is the differentiator: alternatives that try to emulate a full POSIX shell on Windows are heavier and slower, while cross-env’s regex-based rewriting of just the variable-reference syntax keeps it a near-zero-overhead prefix to any existing script.

Used by 118 apps in this directory

TypeScript
100%
AGPL 3.0

RSSHub

Automation · Social Media

46,339

Turn any website into an RSS feed — social media, streaming platforms, and niche sites all become subscribable in seconds.

View details
94
Repo Health
82
Technical
72
Dependency
Built with
TypeScript 100%
Updated 1 weeks ago
TypeScript
65%
MIT

Scalar

Developer Tools

16,198

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 1 weeks ago
JavaScript
89%
GPL 3.0

Screenity

Productivity · Video Editors

18,731

Free, privacy-first Chrome screen recorder with real-time annotation, AI camera blur, and a built-in video editor — no sign-in or limits required.

View details
76
Repo Health
62
Technical
70
Dependency
Built with
JavaScript 89%
Updated 2 weeks ago
TypeScript
64%
AGPL 3.0

Silex

Design Tools · No Code Platforms

2,986

Free, open-source visual website builder that exports clean HTML/CSS — no lock-in, no subscription, host anywhere

View details
89
Repo Health
68
Technical
67
Dependency
Built with
TypeScript 64%
Rust 15%
JavaScript 11%
Updated 1 weeks ago
TypeScript
97%
Other

Sourcebot

AI Code Assistants · Developer Tools · Search

3,952

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
85
Repo Health
83
Technical
62
Dependency
Built with
TypeScript 97%
Updated 2 weeks ago
TypeScript
88%
Other

strapi

CMS

73,243

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
66
Dependency
Built with
TypeScript 88%
JavaScript 12%
Updated 1 weeks ago
TypeScript
91%
MIT

Super Productivity

Productivity · Project Management

22,309

A privacy-respecting, local-first task manager with built-in timeboxing, Pomodoro timer, and deep integrations for Jira, GitHub, GitLab, and CalDAV — no accounts, no data collection, ever.

View details
91
Repo Health
81
Technical
72
Dependency
Built with
TypeScript 91%
Updated 1 weeks ago
TypeScript
96%
Other

superglue

AI Agents · Data Engineering · Developer Tools

2,063

superglue is an AI-agent-driven integration engine that turns plain-English descriptions of enterprise systems into production-grade API tools, ERP/CRM connectors, and data pipelines — self-hosted or cloud, Y Combinator-backed (W25).

View details
49
Repo Health
79
Technical
67
Dependency
Built with
TypeScript 96%
Updated 1 months ago
TypeScript
85%
Apache 2.0

superset

AI Code Assistants · AI Development

14,690

Orchestrate an army of AI coding agents—Claude Code, Codex, Gemini CLI, and more—running simultaneously in isolated git worktrees from a single Electron desktop app.

View details
86
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 85%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers