NPM vs JAM, RequireJS vs Browserify vs Ender : javascript


So npm and jam are both package managers. Npm focuses on back-end javascript modules for node.js. These modules are CommonJS modules See the Spec - People (myself included) have tried hijacking that module system to get the same awesomeness on the front-end. It doesn't work out so well because you're probably not using CommonJS modules on the front-end all the time.



 
 

Related Links:

Content

Cached Text (at the time of saving)


I'm actually working a lot with jam right now.
So npm and jam are both package managers. Npm focuses on back-end javascript modules for node.js. These modules are CommonJS modules See the Spec - People (myself included) have tried hijacking that module system to get the same awesomeness on the front-end. It doesn't work out so well because you're probably not using CommonJS modules on the front-end all the time. And the commonJS is admittedly weak Ryan Dahl regrets using it
Why would you want that on the front-end? Well, the same reason you'd want it on the back-end: You don't want to deal with the stupid crap that comes with installing/managing dependencies and their many versions. I should be able to setup a new project, enter in the dependencies I need and have a package manager fetch everything required to get going. In addition, if I need something later down the line, I shouldn't have to hunt down a version of a module that works with my stack. I should be able to do something like "npm install package." Jam is the package manager that allows you to do that for AMD specified modules.
AMD specified modules were designed with the Web in mind. They're more flexible (your module doesn't HAVE to be a damn object) and I think they're more in line with Harmony Modules - Maybe not though.
Jam is the Npm of the web (at least that's the hope!). It has its own registry separate from npm. Which makes sense. You don't want to mix the two as they have different needs. Lesscss for node.js is different than Lesscss for the browser and the browser doesn't need all the unnecessary build tools and who-watchits. Its registry is still in its infancy and the creator, Caolan McMahon has informed me he'll be moving the site to its own domain soon. I'm working on getting more modules up.
Browserify will enable you to more easily hijack the Npm registry as it allows you to load in CommonJS specified modules in the browser. However, NPM will not help you much with dependency management as it nests dependencies inside the the modules themselves. So you might end up downloading and requiring the same module multiple times. In addition, modules in the npm registry aren't guaranteed to work in the browser. So, Browserify is a dependency and javascript module loader that uses CommonJS modules and works in tandem with NPM.
RequireJS uses the AMD spec and works in tandem with Jam. RequireJS is a lot less intuitive for the web at first but once you get the hang of it, it can actually be really beautiful. Especially if you're using Jam. It focuses on the fact that on the web, modules are loaded asynchronously. It forces you develop in a different style, but the style is great. You may already be developing in that style and you're using something more lightweight like LabJS . And you're probably saying, why the hell do I need to add all the extra crap? Well, once you use Jam like you use Npm on the back-end, you'll never want to go back. Plus, Require really enforces asynchronous programming.
Ender is another attempt at hijacking the Npm registry, but at the same time, it is its own script-loader/dependency manager. Ender downloads modules from the Npm registry, places them in a node_modules folder, and keeps tracks of all the files your project needs. It creates and maintains a single javascript file with all of your modules under a single namespace. This is a lot better than browserify in my opinion. I love using ender. Ender allows you to build your own frameworks like jquery without all the bloat using small commonJs modules.
But Ender suffers the same drawbacks as Browserify: It's utilizing a registry and module specification that isn't for the browser. So there will have to be extra work to get them to work.
Jam and Require seek to remedy this by creating a repository specifically for the browser and a module loading system with the browser in mind.