Detect if JS is running under Node
Published on 2 July 2014 at 10:26 by
Here is a snippet for how to detect if JavaScript is running under Node:
var isNode = typeof process !== "undefined" &&
{}.toString.call(process) === "[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.