Adam K Dean

Detect if JS is running under Node

Published on 2 July 2014 at 10:26 by Adam

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.



This post was first published on 2 July 2014 at 10:26. It was filed under archive with tags node, snippet, javascript.