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