detect-node-es

中文文档
1.1.0发布于 2021/03/18MITTypeScriptESM + CJS零依赖近 30 天下载 3亿

Detect Node.JS (as opposite to browser environment). ESM modification

原始使用文档
文档目录3 节
  1. detect-node
  2. Install
  3. Usage:

detect-node

This is a fork of detect-node.

Differences:

  • uses named export {isNode}
  • has d.ts integrated
  • supports ESM

Install

npm install --save detect-node-es

Usage:

-var isNode = require('detect-node');
+var {isNode} = require('detect-node-es');

if (isNode) {
  console.log("Running under Node.JS");
} else {
  alert("Hello from browser (or whatever not-a-node env)");
}

The check is performed as:

module.exports = false;

// Only Node.JS has a process variable that is of [[Class]] process
try {
 module.exports = Object.prototype.toString.call(global.process) === '[object process]' 
} catch(e) {}

Thanks to Ingvar Stepanyan for the initial idea. This check is both the most reliable I could find and it does not use process env directly, which would cause browserify to include it into the build.

版本与发布记录

detect-node-es 共发布 2 个版本,首次发布于 2020/07/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.0latest2021/03/185 年前
1.0.02020/07/276 年前

关于 detect-node-es 的常见问题

detect-node-es 是什么?

Detect Node.JS (as opposite to browser environment). ESM modification

如何安装 detect-node-es?

在项目目录运行 npm install detect-node-es,或使用 pnpm add / yarn add / bun add。

detect-node-es 支持 TypeScript 吗?

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

detect-node-es 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

detect-node-es 可以商用吗?

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

detect-node-es 的下载量有多少?

根据 npm 官方下载统计,detect-node-es 在 2026/10/07 – 2026/11/05 这 30 天内被下载 303,696,633 次,日均约 10,123,221 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

detect-node-es 还在维护吗?

最新版本 1.1.0 发布于 2021/03/18(5 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/07/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。