Warning detect-runtime has been deprecated in favor of std-env (since version 3.4.0), which includes the same functionalities and much more.
Small library to detect the current JavaScript runtime. The list of supported runtimes is based on the WinterCG Runtime Keys proposal:
edge-routineAlibaba Cloud Edge RoutineworkerdCloudflare WorkersdenoDeno and Deno DeploylagonLagonreact-nativeReact NativenetlifyNetlify Edge FunctionselectronElectronnodeNode.jsbunBunedge-lightVercel Edge FunctionsfastlyFastly Compute@Edge
This package is properly typed and exported to both ESM and CJS.
detect-runtime is published on NPM:
# NPM
npm install detect-runtime
# Yarn
yarn add detect-runtime
# PNPM
pnpm install detect-runtime
# Bun
bun install detect-runtimeOr in Deno:
import { ... } from 'npm:detect-runtime'Import and call the detectRuntime() function from the detect-runtime package:
import { detectRuntime } from 'detect-runtime'
const runtime = detectRuntime()
// ^? 'edge-routine' | 'workerd' | 'deno' | 'lagon' | 'react-native' | 'netlify | 'electron | 'node | 'bun | 'edge-light | 'unknown'You can also import the Runtime type which is the return type of detectRuntime().