std-env

中文文档
4.3.0发布于 2026/09/29MITTypeScriptES Module零依赖近 30 天下载 5.6亿

Runtime agnostic JS utils

原始使用文档
文档目录6 节
  1. Runtime Detection
  2. Provider Detection
  3. Agent Detection
  4. Flags
  5. Environment
  6. License

std-env

npm version npm downloads bundle size

Runtime-agnostic JS utils for detecting environments, runtimes, CI providers, and AI coding agents.

Runtime Detection

Detects the current JavaScript runtime based on global variables, following the WinterCG Runtime Keys proposal.

import { runtime, runtimeInfo } from "std-env";

console.log(runtime); // "" | "node" | "deno" | "bun" | "workerd" ...
console.log(runtimeInfo); // { name: "node" }

Individual named exports: isNode, isBun, isDeno, isNetlify, isEdgeLight, isWorkerd, isFastly, isNub

[!NOTE] isNode is also true in Bun/Deno with Node.js compatibility mode. Use runtime === "node" for strict checks.

isNub detects Nub, which augments Node.js rather than replacing it. It is additive: isNode is also true and runtime stays "node".

See ./src/runtimes.ts for the full list.

Provider Detection

Detects the current CI/CD provider based on environment variables.

import { isCI, provider, providerInfo } from "std-env";

console.log({ isCI, provider, providerInfo });
// { isCI: true, provider: "github_actions", providerInfo: { name: "github_actions", ci: true } }

Use detectProvider() to re-run detection. See ./src/providers.ts for the full list.

Agent Detection

Detects if the environment is running inside an AI coding agent.

import { isAgent, agent, agentInfo } from "std-env";

console.log({ isAgent, agent, agentInfo });
// { isAgent: true, agent: "claude", agentInfo: { name: "claude" } }

Set the AI_AGENT env var to explicitly specify the agent name. GitHub Copilot aliases github_copilot_vscode_agent and github_copilot_cloud_agent are normalized to copilot. Use detectAgent() to re-run detection.

Supported agents: cursor, claude, copilot, devin, replit, gemini, codex, auggie, opencode, kiro, goose, pi, junie

Flags

import { env, isDevelopment, isProduction } from "std-env";
ExportDescription
hasTTYstdout TTY is available
hasWindowGlobal window is available
isCIRunning in CI
isColorSupportedTerminal color output supported
isDebugDEBUG env var is set
isDevelopmentNODE_ENV is dev/development or MODE is development
isLinuxLinux platform
isMacOSmacOS (darwin) platform
isMinimalMINIMAL env is set, CI, test, or no TTY
isProductionNODE_ENV or MODE is production
isTestNODE_ENV is test or TEST env is set
isWindowsWindows platform
platformValue of process.platform
nodeVersionNode.js version string (e.g. "22.0.0")
nodeMajorVersionNode.js major version number (e.g. 22)

See ./src/flags.ts for details.

Environment

ExportDescription
envUniversal process.env (works across all runtimes)
processUniversal process shim (works across all runtimes)
nodeENVCurrent NODE_ENV value (undefined if unset)

License

MIT

版本与发布记录

std-env 共发布 41 个版本,首次发布于 2018/03/31;过去 12 个月发布了 5 个版本。

版本发布日期距今
4.3.0latest2026/09/291 个月前
4.2.02026/07/083 个月前
4.1.02026/04/156 个月前
4.0.02026/03/107 个月前
4.0.0-rc.12026/02/188 个月前
3.10.02025/10/141.1 年前

关于 std-env 的常见问题

std-env 是什么?

Runtime agnostic JS utils

如何安装 std-env?

在项目目录运行 npm install std-env,或使用 pnpm add / yarn add / bun add。

std-env 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

std-env 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

std-env 可以商用吗?

std-env 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

std-env 的下载量有多少?

根据 npm 官方下载统计,std-env 在 2026/10/05 – 2026/11/03 这 30 天内被下载 557,753,602 次,日均约 18,591,787 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

std-env 还在维护吗?

最新版本 4.3.0 发布于 2026/09/29(1 个月前);至今共发布 41 个版本,其中过去 12 个月发布了 5 个;首次发布于 2018/03/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。