Skip to content

Instantly share code, notes, and snippets.

@jeshuamaxey
Last active August 29, 2015 13:56
Show Gist options
  • Save jeshuamaxey/8830600 to your computer and use it in GitHub Desktop.
Save jeshuamaxey/8830600 to your computer and use it in GitHub Desktop.
Pop this at the end of your node module and it can be used equally well in a browser too
/*
* all credit to @matteoagosti
* http://www.matteoagosti.com/blog/2013/02/24/writing-javascript-modules-for-both-browser-and-node/
*/
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
//export for node
module.exports = /*MODULE_OBJECT*/ ;
}
else {
//export for browser
window./*MODULE_OBJECT*/ = /*MODULE_OBJECT*/;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment