Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

detect-node

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Issues
File Explorer

Advanced tools

detect-node

Detect Node.JS (as opposite to browser environment) (reliable)

    2.1.0latest

Version published
Maintainers
1
Weekly downloads
12,381,310
decreased by-4.96%

Weekly downloads

Readme

Source

Install

npm install --save detect-node

Usage:

var isNode = require('detect-node'); if (isNode) { console.log("Running under Node.JS"); } else { alert("Hello from browser (or whatever not-a-node env)"); }

The check is performed as:

module.exports = false; // Only Node.JS has a process variable that is of [[Class]] process try { module.exports = Object.prototype.toString.call(global.process) === '[object process]' } catch(e) {}

Thanks to Ingvar Stepanyan for the initial idea. This check is both the most reliable I could find and it does not use process env directly, which would cause browserify to include it into the build.

Keywords

FAQs

What is detect-node?

Detect Node.JS (as opposite to browser environment) (reliable)

Is detect-node popular?

The npm package detect-node receives a total of 11,782,074 weekly downloads. As such, detect-node popularity was classified as popular.

Is detect-node well maintained?

We found that detect-node demonstrated a not healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 16 May 2021
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc