Skip to content

Detects the current runtime environment (Node.js, Cloudflare Workers, Deno, ...)

License

Notifications You must be signed in to change notification settings

QuiiBz/detect-runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

detect-runtime

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-routine Alibaba Cloud Edge Routine
  • workerd Cloudflare Workers
  • deno Deno and Deno Deploy
  • lagon Lagon
  • react-native React Native
  • netlify Netlify Edge Functions
  • electron Electron
  • node Node.js
  • bun Bun
  • edge-light Vercel Edge Functions
  • fastly Fastly Compute@Edge

This package is properly typed and exported to both ESM and CJS.

Installation

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-runtime

Or in Deno:

import { ... } from 'npm:detect-runtime'

Usage

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().

License

MIT

About

Detects the current runtime environment (Node.js, Cloudflare Workers, Deno, ...)

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published