software engineering

Detect if JS is running under Node

By Adam K Dean on

Here is a snippet for how to detect if JavaScript is running under Node:

var isNode = typeof process !== "undefined" && 
    {} === "[object process]";

We check here whether the variable process is defined, and if it is, we check it's type to make sure it's the proper process object and not just a regular old JavaScript object.