Detect the JavaScript runtime
mainUse std-env to identify the current execution environment (e.g., Node.js, Bun, Deno, or Workerd) following the WinterCG Runtime Keys proposal.
Strict vs. Compatibility Checks:
- Use
runtime === 'node'for a strict check to ensure you are specifically in Node.js. - Use
isNodeif you want to include Bun or Deno when they are running in Node.js compatibility mode.
Available named boolean exports include isNode, isBun, isDeno, isNetlify, isEdgeLight, isWorkerd, and isFastly.
import { runtime, runtimeInfo } from "std-env";
console.log(runtime); // "" | "node" | "deno" | "bun" | "workerd" ...
console.log(runtimeInfo); // { name: "node" }