Skip to content

Instantly share code, notes, and snippets.

@tcr
Last active December 10, 2015 23:18
Show Gist options
  • Select an option

  • Save tcr/4508262 to your computer and use it in GitHub Desktop.

Select an option

Save tcr/4508262 to your computer and use it in GitHub Desktop.
How can you detect browser vs. Node.js vs CommonJS?
var isNode = typeof process != 'undefined' && process.versions && process.versions.node;

var isBrowser = typeof window != 'undefined';  

var isModule = typeof module != 'undefined' && module.exports;
["javascript","node.js","browser","commonjs","module"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment