Socket
Socket
Sign inDemoInstall

environment

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

environment

Check which JavaScript environment your code is running in at runtime: browser, Node.js, Bun, etc


Version published
Maintainers
2
Created
Source

environment

Check which JavaScript environment your code is running in at runtime

Install

npm install environment

Usage

import {isBrowser, isNode} from 'environment';

if (isBrowser) {
	console.log('Running in a browser!');
}

if (isNode) {
	console.log('Running in Node.js!');
}

[!NOTE] Runtime checks should be used sparingly. Prefer conditional package exports and imports whenever possible.

API

isBrowser

Check if the code is running in a web browser environment.

isNode

Check if the code is running in a Node.js environment.

isBun

Check if the code is running in a Bun environment.

isDeno

Check if the code is running in a Deno environment.

isElectron

Check if the code is running in an Electron environment.

isJsDom

Check if the code is running in a jsdom environment.

isWebWorker

Check if the code is running in a Web Worker environment, which could be either a dedicated worker, shared worker, or service worker.

isDedicatedWorker

Check if the code is running in a Dedicated Worker environment.

isSharedWorker

Check if the code is running in a Shared Worker environment.

isServiceWorker

Check if the code is running in a Service Worker environment.

  • is - Type check values

Keywords

FAQs

Package last updated on 28 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc