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

PHP
85%
Other

Invoice Ninja

Invoicing Finance · Project Management

10,123

Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.

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

Jaaz

AI Agents · AI Design Tools

6,670

Open-source AI creative agent that turns visual sketches and canvas gestures into images and videos — no text prompts required.

View details
48
Repo Health
59
Technical
71
Dependency
Built with
TypeScript 55%
Python 34%
JavaScript 10%
Updated 7 months ago
Rust
52%
Other

Jan

AI Assistants

44,680

Run LLMs 100% locally with full privacy, or connect to cloud AI — your machine, your data, your control.

View details
90
Repo Health
81
Technical
65
Dependency
Built with
Rust 52%
TypeScript 44%
Updated 1 weeks ago
TypeScript
50%

Kener

Devops · Monitoring

5,181

Stunning, self-hosted status pages with real-time uptime monitoring, incident management, and multi-channel notifications in a single Docker container.

View details
86
Repo Health
76
Technical
67
Dependency
Built with
TypeScript 50%
Svelte 47%
Updated 3 weeks ago
Java
58%
Apache 2.0

Kestra

Automation · Data Engineering · Devops

28,388

Event-driven orchestration platform for data, AI, and infrastructure workflows — define everything in YAML, run anywhere at scale.

View details
93
Repo Health
81
Technical
72
Dependency
Built with
Java 58%
TypeScript 26%
Vue 15%
Updated 2 weeks ago
TypeScript
82%
MIT

LibreChat

AI Assistants · Developer Tools

45,009

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 82%
JavaScript 17%
Updated 1 weeks ago
JavaScript
43%
Other

LimeSurvey

Forms Surveys

3,736

The world's most flexible open-source survey platform with 900+ templates, conditional logic, 80+ languages, and full GDPR compliance for any scale.

View details
86
Repo Health
62
Technical
63
Dependency
Built with
JavaScript 43%
PHP 35%
CSS 12%
Updated 1 weeks ago
TypeScript
99%
Other

LobeHub

AI Assistants · Automation · Productivity

82,864

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
Clojure
70%
AGPL 3.0

Logseq

Knowledge Management · Note Taking

45,069

A privacy-first, open-source knowledge graph platform combining Markdown, Org-mode, bidirectional linking, and local-first storage for building your second brain.

View details
92
Repo Health
82
Technical
68
Dependency
Built with
Clojure 70%
OCaml 12%
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