Package Management

Every language benefits from a standardized method for sharing code.
JavaScript provides multiple options.

Bower
Bower used to be a very popular option but more people have started moving to npm.
Bower became popular by supporting the entire web platform and packaging libraries in a format that didn’t require build step. Today, nearly everyone has a build step because they are transpiling, minifying, linting and so on.
So bower has become mostly irrelevant.

NPM
It stands for Node Package Manager. Node has grown wildly in popularity and bundlers continue to become powerful. Hence, it has become a de-facto standard for JavaScript package managers. Today, npm is clearly the most popular package manager for JavaScript.

It offers almost everything that you need.

JSPM
It stands for JavaScript package manager. It is frictionless browser package management

  • It allows you to install packages from its own list of repositories as well as from other locations including npm, github and bower. It also bundles your code.
  • For development, load modules as separate files with ES6 and plugins compiled in the browser.
  • For production (or development too), optimize into a bundle, layered bundles or a self-executing bundle with a single command.

There are some other less popular options like

Jam
Jam is a package manager for JavaScript.

It has features like:

  • Manage dependencies
  • Fast and modular
  • Use with existing stack
  • Custom builds
  • Focus on size

Volo
volo is a tool which lets you quickly create projects, add libraries, and automate common tasks using node and JavaScript.

It creates browser-based, front-end projects from project templates, and add dependencies by fetching them from GitHub. Once your project is set up, automate common tasks.

Getting started with Node Package Manager

Creating package.json

To create a package.json run:
npm init

This will initiate a command line questionnaire that will conclude with the creation of a package.json in the directory you initiated the command.

Package.json file contents:

  • name: name of the project
  • version: initial version. Default 1.0.0
  • description: description of project
  • scripts: by default creates a empty test script. It helps to automate processes.
  • keywords: empty
  • author: whatever you provided the CLI
  • license: ISC
  • dependencies – Production dependencies
  • devDependencies – Development Dependencies
  • repository: will pull in info from the current directory, if present
  • bugs: will pull in info from the current directory, if present
  • homepage: will pull in info from the current directory, if present

Sample package.json

{
“name”: “Sample javascript project”,
“version”: “1.0.0”,
“description”: “Sample project in JavaScript”,
“scripts”: {
“start”: “npm start”,
},
“author”: “xyz”,
“license”: “MIT”,
“dependencies”: {
“favicon”: “0.0.2”,
“http”: “0.0.0”,
“jade”: “*”,
“mongojs”: “^2.4.0”,
“path”: “^0.12.7”,
“router”: “^1.1.4”
},
“devDependencies”: {
“babel-cli”: “6.16.0”,
“babel-core”: “6.17.0”,
“babel-loader”: “6.2.5”,
“babel-preset-latest”: “6.16.0”,
“babel-register”: “6.16.3”,
“chai”: “3.5.0”,
“eslint”: “3.8.1”,
“express”: “4.14.0”,
“jsdom”: “9.8.0”,
“localtunnel”: “1.8.1”,
“mocha”: “3.1.2”,
“nock”: “8.1.0”,
“npm-run-all”: “3.1.1”,
“nsp”: “2.6.2”,
“numeral”: “1.5.3”,
“style-loader”: “0.13.1”,
“surge”: “0.18.0”,
“webpack”: “1.13.2”,
“webpack-md5-hash”: “0.0.5”
}
}

To install the above packages:
Go to the path where package.json is present.

Type >npm install (Require internet connection).

Once this is done, you can see a node_modules folder under the same path containing all the above package along with the dependent modules.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s