A few ideas:
You can check the global window object, if available, you are in the browser
if (typeof window === 'undefined')
// this is node
Or you can check the process object, if available, you are in node
if(typeof process === 'object')
// this is also node
source
share