JavaScript
Check for Node.js environment

by Benny Neugebauer

const isNode = (typeof module !== 'undefined' && typeof module.exports !== 'undefined');

const isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';

Another possibility: const isNode = !!window;

Benny Neugebauer

Sign in to comment!