Extending Modules
Video Course on Real-Time HTML5 with Node.jstalks about browserify
use an npm module in the browser - if it uses node libraries
like
events
, stream
, path
, url
<- these can work in the browser UMD module pattern
how to run the same code on server and client and AMD module environment.
you just need to change "
YourModuleName
"
(function UMD(name,context,definition){
if (typeof module !== "undefined" && module.exports) { module.exports = definition(); }
else if (typeof define === "function" && define.amd) { define(definition); }
else { context[name] = definition(name,context); }
})("YourModuleName",this,function DEF(name,context){
var publicAPI = { /*..*/ };
return publicAPI;
});
checks the environment it runs in if Node or Client (browser) or AMD and uses accordingly so your code can run in all three environments
so you can use it instead of the
module.exports
pattern