NPM : Package json

Using package json to Define Dependencies :

When coding a Node application, you have to include a package json file at the root. The

package.json file is where you can define some of your application metadata, such as the

name, authors, repository, contacts, and so on.

You don’t need to use it to publish the application to NPM — you may want to keep that

application  private — but you can still use package.json to specify the application


The package.json is a JSON-formatted file that can contain a series of attributes, but for the pur-

poses of declaring the dependencies . An application that depends on the express , nano , and request

packages could have a  package.json file like this:


“name” : “myApp”,

“version” : “1.0.0”,

“dependencies” : {

“express” : “4.3.x”,

“nano” : “*”,

“request” : “>0.2.0”



Here you are specifying that your application or module depends on express version 4.3, on any version of nano , and on any version of request greater than 0.2.0.

Then, on the application root, type:

$ npm install

NPM will then analyze the dependencies and your node_modules directory and automatically

download and install any missing packages.

You can also update all the locally installed packages to the latest version that meets your dependency specifications, like this:

$ npm update

In fact you can always use this last command, because it will also make NPM fetch any missing packages.

More information on Package.json :Package.json


My Name is Dileep Singh, Noder, Javascript Lover & NoSql Developer, Fitness Freak, Love to travel new places, learning photography & Music Manic ♯ ♩ ♬

Posted in Node.Js Tagged with: