Skip to content

Env

The env module provides utility functions to detect and interact with the code execution environment, including:

  • Detection of operating system and runtime (Node.js, Deno, Bun, browser)
  • Environment checking (development/production)
  • Manipulation of environment variables
  • Detection of context type (server, browser, workers)
  • Mobile device identification

All functions are optimized to work in different environments and return consistent results regardless of platform.

Overview

equalsEnv

typescript
equalsEnv(env: string): boolean;

Checks if the current environment matches the given value (env).

getEnv

typescript
getEnv(key: string): string | undefined;

Gets the value of an environment variable.

getOS

typescript
getOS(): 'windows' | 'macos' | 'linux' | 'android' | 'ios' | 'unknown';

Detects the current operating system.

getRuntime

typescript
getRuntime(): 'node' | 'deno' | 'bun' | 'browser' | 'unknown';

Detects the execution runtime.

hasEnv

typescript
hasEnv(key: string): boolean;

Checks if an environment variable is set.

isBrowser

typescript
isBrowser(): boolean;

Checks if the code is running in a browser.

isBun

typescript
isBun(): boolean;

Checks if the code is running in the Bun environment.

isDedicatedWorker

typescript
isDedicatedWorker(): boolean;

Checks if the code is running in a Dedicated Worker.

isDeno

typescript
isDeno(): boolean;

Checks if the code is running in the Deno environment.

isDev

typescript
isDev(): boolean;

Checks if the environment is in development mode.

isMobile

typescript
isMobile(): boolean;

Checks if the code is running on a mobile device.

isNode

typescript
isNode(): boolean;

Checks if the code is running in Node.js.

isProd

typescript
isProd(): boolean;

Checks if the environment is in production mode.

isServer

typescript
isServer(): boolean;

Checks if the code is running in a server environment (not browser).

isServiceWorker

typescript
isServiceWorker(): boolean;

Checks if the code is running in a Service Worker.

isWebWorker

typescript
isWebWorker(): boolean;

Checks if the code is running in any type of Web Worker.

Released under the MIT License.