cross-env
Cross-platform environment variable setter for npm scripts. Allows setting environment variables in package.json scripts that work consistently on Unix (macOS, Linux) and Windows. On Unix, 'NODE_ENV=production node app.js' works natively; on Windows it doesn't. cross-env solves this: 'cross-env NODE_ENV=production node app.js' works on all platforms. Created by Kent C. Dodds. Now in maintenance mode — covered by native solutions on modern platforms.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Env var injection — don't use for secrets in scripts visible in git history. Local-only execution. No network surface.
⚡ Reliability
Best When
You have a Node.js project with developers on both Windows and Unix, and npm scripts that set environment variables.
Avoid When
Your team is Unix-only, or you're on Node.js 20+ where native cross-platform env var support has improved, or you use a package manager (Bun) with built-in support.
Use Cases
- • Set NODE_ENV=production/development/test in npm scripts that must run on both Windows and Unix developer machines
- • Pass environment variables to build scripts (webpack, Vite, rollup) cross-platform without shell-specific syntax
- • Standardize environment variable syntax in package.json scripts across Windows and Unix dev teams
- • Set multiple environment variables for test configurations in cross-platform test runner scripts
- • Configure environment-specific settings in npm run scripts without PowerShell or bash conditionals
Not For
- • Secret management — don't put sensitive values in package.json scripts; use .env files with dotenv
- • Production environment configuration — use platform-specific env var injection (Docker ENV, Heroku Config Vars)
- • Runtime environment detection — use process.env directly in code for reading env vars
Interface
Authentication
No authentication — CLI utility.
Pricing
Fully free, MIT licensed.
Agent Metadata
Known Gotchas
- ⚠ cross-env is now in maintenance mode — for new projects, consider npm v7+ workspaces or platform-native solutions; cross-env still works but won't get new features
- ⚠ Values with spaces require quotes: cross-env MY_VAR='hello world' node app.js — quoting syntax varies by shell; test on target platforms
- ⚠ cross-env doesn't handle .env files — it only sets variables from command-line arguments; use dotenv for .env file loading
- ⚠ Don't put secrets in package.json scripts with cross-env — package.json is committed to git; use dotenv or CI/CD secrets for sensitive values
- ⚠ Windows PowerShell and cmd.exe both supported — cross-env normalizes the syntax so the underlying shell doesn't matter
- ⚠ cross-env-shell variant available for scripts that need shell processing (glob expansion, pipes) — regular cross-env spawns command directly without shell
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for cross-env.
Scores are editorial opinions as of 2026-03-06.