
\begin{DoxyCode}{0}
\DoxyCodeLine{npm install -\/-\/save detect-\/node }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_detect_node_Readme_autotoc_md8139}{}\doxysubsection{Usage\+:}\label{md_sfcode_node_modules_detect_node_Readme_autotoc_md8139}

\begin{DoxyCode}{0}
\DoxyCodeLine{var isNode = require('detect-\/node');}
\DoxyCodeLine{}
\DoxyCodeLine{if (isNode) \{}
\DoxyCodeLine{  console.log("{}Running under Node.JS"{});}
\DoxyCodeLine{\} else \{}
\DoxyCodeLine{  alert("{}Hello from browser (or whatever not-\/a-\/node env)"{});}
\DoxyCodeLine{\} }

\end{DoxyCode}


The check is performed as\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{module.exports = false;}
\DoxyCodeLine{}
\DoxyCodeLine{// Only Node.JS has a process variable that is of [[Class]] process}
\DoxyCodeLine{try \{}
\DoxyCodeLine{ module.exports = Object.prototype.toString.call(global.process) === '[object process]' }
\DoxyCodeLine{\} catch(e) \{\}}

\end{DoxyCode}


Thanks to Ingvar Stepanyan for the initial idea. This check is both {\bfseries{the most reliable I could find}} and it does not use {\ttfamily process} env directly, which would cause browserify to include it into the build. 