5

What is the difference between package.json vs bower.json.?

what is the criteria that we should consider before defining the dependencies in both files.

And what difference will it make by running "bower install" and "npm install" ?

LearnAngular
  • 71
  • 2
  • 8
  • 1
    This question has already been asked: http://stackoverflow.com/questions/21198977/difference-between-grunt-npm-and-bower-package-json-vs-bower-json – Kevin Restiaens Feb 29 '16 at 10:52
  • i would even like to know the criteria that we should consider for defining dependencies in bower.json and package.json – LearnAngular Feb 29 '16 at 11:02

3 Answers3

5

NPM (package.json)

npm is most commonly used for managing Node.js modules, but it works for the front-end too when combined with Browserify and/or $ npm dedupe.

Bower (bower.json)

Bower is created solely for the front-end and is optimized with that in mind. The biggest difference is that npm does nested dependency tree (size heavy) while Bower requires a flat dependency tree (puts the burden of dependency resolution on the user).

A nested dependency tree means that your dependencies can have their own dependencies which can have their own, and so on. This is really great on the server where you don't have to care much about space and latency. It lets you not have to care about dependency conflicts as all your dependencies use e.g. their own version of Underscore. This obviously doesn't work that well on the front-end. Imagine a site having to download three copies of jQuery.

In short, NPM aims for stability. Bower aims for minimal resource load. If you draw out the dependency structure.

1

npm dependencies are defined or added to package.json. Bower dependencies are in bower.json.

Martin
  • 15,820
  • 4
  • 47
  • 56
  • Thanks for your comment. I am new to angular and i am trying to learn each module. can you please tell me what is npm dependency and bower dependencies.? – LearnAngular Feb 29 '16 at 10:57
  • Npm and bower are both Javascript package managers. A npm dependancy would be a package that you included into your project with npm. Like, angular, for example. – Martin Feb 29 '16 at 20:34
1

** Package.json file is for node related package manager while bower can manage application level package dependencies. I like bower more.

** We need to find which dependencies related to development and which are production.

** "bower install" -- Install all dependencies mentioned in Dependencies object. ** "bower install -D" -- Install all dependencies mentioned in DevDependencies object.

Same with Npm Install and npm install -D

Faiz Ahmad
  • 33
  • 5