NPM Samjha karo (NPM please understand)

If you are any one who has worked with frontend the chances are high that you know what NPM is. For the uninitiated NPM is Node Package Manager, which helps you get your dependency installed on the system easily, infact easily is the term which I have issues with.

So if you want JQuery, no need to download it manually, you just say npm install jquery and see the magic, it would go to internet and get you JQuery.

The concept of package manager is not something new, most of the Linux system have their own package manager like aptitude or apt on Ubuntu or Debian, yum on RedHat, CentOS, HomeBrew for Mac, even in frameworks there are package managers like gem for Ruby, maven and ivy for Java. The basic purpose of package manager is to get the usable dependency installed on your system.

The important point to notice is usable, lets consider the example of the non package manager way of installing dependency, you get hold of a source code in a zip or tar format, in linux world, this would be a tarball. You unzip the source and run make which would compile the source and create a installable for your system. If you use a package manager, you can avoid using these steps and it would simply download the installable file and install on your system.

In case of interpreted languages like JavaScript, PHP and others, the source is the dependency, so if you use package managers like Composer for PHP, it would download the source.

So what does NPM do so different, for me to even write this post. NPM or javascript package managers do not have a concept of usable dependency, so they download the entire github repository for you. So if you only wanted JQuery as a dependency, it would download the entire repository of JQuery, which may not be much (if you do not mind download 1.3 MB instead of 87KB), but lets say if you need something more complex like Browserify, it would load all repository of all dependency.

So if you are trying to build a simple html website or SPA (Single Page Application) and you need bootstrap, angular JS, you would have a node_modules folder running into few hundreds MB. Agreed that it does not go into build but still it is downloading loads of stuffs which you do not need. Now compare that to manually downloading a few kb of files and linking them, when you see it that ways, it brings me to question the entire utility of such a package manager and here I would generalise to all the package managers like bower, npm and other similar package managers.

A package manager has to work like a package manager, not a download manager. We really really need a distributable file concept in JS, and actually we do have one. Most of the time if you are manually downloading, you would simple get the minified file and link them. So why cant we have a package manager which only downloads minified linkable dependency.

The way these package managers work is when you want a banana, you get a banana with a 300 lb guerilla holding the banana and the entire jungle with it, but hey, you got the banana, right!