
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
browser-or-node
Advanced tools
Check in which environment the code is running - browser/node.js/webworker/jsdom/deno
The 'browser-or-node' npm package is a utility that helps developers determine whether their code is running in a browser or Node.js environment. This can be particularly useful for writing isomorphic JavaScript that needs to behave differently depending on the runtime environment.
Detect if running in a browser
This feature allows you to check if the code is being executed in a browser environment. The 'isBrowser' boolean will be true if the code is running in a browser.
const { isBrowser } = require('browser-or-node');
if (isBrowser) {
console.log('Running in a browser');
}
Detect if running in Node.js
This feature allows you to check if the code is being executed in a Node.js environment. The 'isNode' boolean will be true if the code is running in Node.js.
const { isNode } = require('browser-or-node');
if (isNode) {
console.log('Running in Node.js');
}
Detect if running in a web worker
This feature allows you to check if the code is being executed in a Web Worker environment. The 'isWebWorker' boolean will be true if the code is running in a Web Worker.
const { isWebWorker } = require('browser-or-node');
if (isWebWorker) {
console.log('Running in a Web Worker');
}
The 'is-browser' package provides a simple way to check if the code is running in a browser environment. It is similar to 'browser-or-node' but does not offer the same level of granularity, such as detecting Node.js or Web Workers.
The 'detect-node' package is a lightweight utility to check if the code is running in a Node.js environment. Unlike 'browser-or-node', it does not provide functionality to detect browser or Web Worker environments.
The 'is-node' package is another utility to determine if the code is running in a Node.js environment. It is similar to 'detect-node' and does not offer the ability to detect browser or Web Worker environments.
Check in which environment the code is running - browser/node.js/webworker/jsdom/deno.
[!NOTE] To help release v3.0.0, please try v3.0.0-pre.0 and let us know if you run into issues.
$ npm install --save browser-or-node
Import the checks and use it in your code. Works with both ESM and CJS imports.
import * as jsEnv from "browser-or-node";
// import { isBrowser, isNode, isWebWorker, isJsDom, isDeno, isBun } from "browser-or-node";
// const jsEnv = require("browser-or-node");
if (jsEnv.isBrowser) {
// do browser only stuff
}
if (jsEnv.isNode) {
// do node.js only stuff
}
if (jsEnv.isWebWorker) {
// do web worker only stuff
}
if (jsEnv.isJsDom) {
// do jsdom only stuff
}
if (jsEnv.isDeno) {
// do deno only stuff
}
if (jsEnv.isBun) {
// do bun only stuff
}
MIT © Dinesh Pandiyan
FAQs
Check in which environment the code is running - browser/node.js/webworker/jsdom/deno
The npm package browser-or-node receives a total of 1,016,058 weekly downloads. As such, browser-or-node popularity was classified as popular.
We found that browser-or-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.