source: trip-planner-front/node_modules/detect-node/Readme.md@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 691 bytes
Line 
1### Install
2
3```shell
4npm install --save detect-node
5```
6
7### Usage:
8
9```js
10var isNode = require('detect-node');
11
12if (isNode) {
13 console.log("Running under Node.JS");
14} else {
15 alert("Hello from browser (or whatever not-a-node env)");
16}
17```
18
19The check is performed as:
20```js
21module.exports = false;
22
23// Only Node.JS has a process variable that is of [[Class]] process
24try {
25 module.exports = Object.prototype.toString.call(global.process) === '[object process]'
26} catch(e) {}
27
28```
29
30Thanks 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.
Note: See TracBrowser for help on using the repository browser.