2

In the projects prarent directory, if I do,

npm init

a file "package.json" is created,

Now if I want to install dependencies like let's say angular, jQuery and bootstrap I can do

npm install angular --save-dev
npm install jquery --save-dev
npm install bootstrap --save-dev

a folder "node_modules" get created, with the above mentioned dependencies.

and the same entries of dependencies in entered in "package.json" .

Now using any build tool like lets say gulp.js,

I can inject the "node_module" dependencies in my SPA's(Single page application) index.html.

So my question is, why to use Bower ?

Please let me know with some pointers

David R
  • 14,711
  • 7
  • 54
  • 72
Rahul Shivsharan
  • 2,481
  • 7
  • 40
  • 59
  • 9
    Possible duplicate of [What is the difference between Bower and npm?](http://stackoverflow.com/questions/18641899/what-is-the-difference-between-bower-and-npm) – JJJ Oct 05 '16 at 08:26
  • In my particular case I use NPM for back-end, while Bower manage just my front-end libs. – Tom Oct 05 '16 at 08:49
  • 2
    I would go just with npm. There is no reason to use 2 different package managers. – Stavros Zavrakas Oct 05 '16 at 08:49
  • 3
    Bower was especially useful a few years ago when not so many front-end based libraries were available through NPM. Nowadays... you don't really need it anymore. The javascript landscape moves at blinding speed, tooling becomes irrelevant quite quickly. – Gimby Oct 05 '16 at 08:56
  • For me npm should be use for all utils dev tool shuch as grunt or karma. And bower for front-end lib. So you use npm for create your project, then bower. For a back end nodejs project i think npm is enought. – amdev Oct 05 '16 at 09:19
  • @amdev What is the benefit of using bower over npm for the frontend (that justifies the additional overhead of *another* tool, *another* configuration file, *another* way of dealing with versions, *another* folder where modules go to, …)? – Golo Roden Oct 05 '16 at 09:23
  • It's explain here http://stackoverflow.com/a/18652918/2606178 and seems approved by the community – amdev Oct 05 '16 at 09:28
  • But, indeed, npm 3 seems close to bower now. But bower seems always most optimized for front end lib management. I don't use npm 3 but I'mn not sure we can just affirm "don't use bower anymore" http://stackoverflow.com/a/27105655/2606178 – amdev Oct 05 '16 at 09:40
  • @amdev This answer is from 2013. – Golo Roden Oct 06 '16 at 14:12

2 Answers2

2

Short answer: Don't (use bower).

Bower started as a "clone" of npm for the client-side, but meanwhile literally everybody is using npm for this, too.

So there is no need to use bower any more, just rely on npm, and everything is fine. It makes your development workflow simpler, more unified, and you just end up with less friction and complexity (which is a good thing).

My biggest concern with bower is that it introduces unneeded overhead, such as another tool, another configuration file, another way of dealing with versions, another folder where modules go to, … I have hardly seen any benefit of bower that outweighs these drawbacks. Again: Just stick to npm and you're fine.

Golo Roden
  • 140,679
  • 96
  • 298
  • 425
  • So, how can you explain why very popular project such as generator-angular from yeoman or jhipster use both npm and bower ?? – amdev Oct 05 '16 at 09:17
  • That's for historical reasons, IMHO. – Golo Roden Oct 05 '16 at 09:18
  • After some reading, I think a new project started in 2016 could use the latest npm3 version without bower but "bower" remains a very lightweight tool so it's not bad to use it but not really necessary anymore. But i'm not sure that npm3 is available with node 4.6 which is LTS so, depends of your company requirement. – amdev Oct 05 '16 at 09:56
  • According to https://github.com/nodejs/LTS Node.js 6 will be the new LTS, starting mid October 2016 (that is, in a few days). So, no need to worry about npm@3 and Node 4. Just use Node 6 and npm@3 and everything is fine. – Golo Roden Oct 06 '16 at 14:14
0

I myself thought of this just yesterday.
From my experience, you can be well off with just npm, provided the packages you need are registered.
This was not the case a few years ago, but now it nearly mirrors bower's repository.

George Kagan
  • 5,913
  • 8
  • 46
  • 50