Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap and Jquery with node js

I would like to know if when I run those 2 commands:

npm install jquery
npm install boostrap

Than I add the two dependecies in my package.json file. Than in my app.js file I code

var $ = require('jquery'); var bootstrap = require('bootstrap');

In my index.ejs file do I need to put a link to a jquery file or a css file or I can use those libraries directly ?

If not, can someone please give the configuration that I need to use bootstrap with npm.

like image 227
anonym Avatar asked Dec 14 '22 06:12

anonym


2 Answers

I would suggest you user bower for this kind of stuff as they are going to be served as static. Bower requires a flat dependency tree, so it's easy to manage dependency conflicts (i.e. multiple jquery file).

To install bower:

npm install -g bower

Install bootstrap using bower:

bower install bootstrap --save

Bootstrap has jquery as it's dependency so it will be installed, you won't need to install it separately.

To see path of installed packages:

bower list --path

Now add those path to your index.ejs file. Currently you will see bootstrap.less path. To add bootstrap.css path you will have to find it manually. I think it's in:

bower_components/bootstrap/dist/css/bootstrap.css

To get a clear idea take a look at this.

Hope it helped you. Thanks!!

like image 133
Sk Arif Avatar answered Dec 29 '22 19:12

Sk Arif


There is also a prebuilt bootstrap bower package called bootstrap-css. I think it will be better to use to keep things minimal and not install unwanted .less files.

bower install bootstrap-css

Thanks....

like image 41
LinuxHub Avatar answered Dec 29 '22 20:12

LinuxHub