Managing NPM dependencies

There are a lot of NPM dependencies in the project, and we have always installed them by hand. But we want to have this package installation process automated, especially if we want others to contribute on the same project.

Every Node.js project can have a package.json file with the definition of the project. We are going to create this file at the root of our project.

At its basics, it is just a simple description of the project, with a name and version:

{
  "name": "investment-tracker",
  "description": "Jasmine Testing Example Application",
  "version": "0.0.1"
}

But it can also be used to define its dependencies:

{
  "name": "investment-tracker",
  "description": "Jasmine Testing Example Application",
  "version": "0.0.1",
  "dependencies": {
    "express": "3.x"
  },
  "devDependencies": {
    "grunt": "0.4.x",
    "grunt-cli": "0.1.x",
    "grunt-exec": "~0.4.0",
    "grunt-contrib-requirejs": "~0.4.0",
    "grunt-contrib-watch": "~0.4.3",
    "grunt-contrib-jshint": "~0.4.3",
    "grunt-contrib-connect": "~0.3.0",
    "requirejs"
  }
}

As a production dependency, we have expressed the framework we used to run our web server in Chapter 4, Asynchronous Testing – AJAX.

As development dependencies, we have everything we need on the development machine, such as grunt and all of its plugins.

So if you come on a new machine and need to install all of these dependencies, just type on the project root folder:

$ npm install

And all those dependencies will be installed for you.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.205.136