Overview


Let's look at how to determine if js code is running in a browser or in node.js

NOTE WELL -- if using the system global we no longer need to use window (browser) or global (node.js), but instead we can now use the standardized myGlobal.

Code


Alternative #1: Variable 'window'
Tapping into js system variable window.
//We can check the js system variable window
const isBrowser = typeof window !== 'undefined';
Alternative #2: Variable 'global'
Tapping into js system variable global.
//We can check the js system variable global
const isNodejs = typeof global !== 'undefined';