DEV Community

Cover image for Detect if JS is running under Node
Adam K Dean
Adam K Dean

Posted on

Detect if JS is running under Node

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.

Latest comments (0)