Using Bootstrap with npm and Node.js

Viewed 4320

I'm having a difficult time understanding where/how to use Bootstrap in my nodejs project. I installed Bootstrap with npm, but how do I include it in my index.html file?

Do I need to include the stylesheet tag at the top and the tags above the tag at the bottom like usual in my .html files, or can I just start applying Bootstrap classes to my elements once I've required it in my app.js file?

Also, is there an advantage to using npm to install Bootstrap versus using the CDNs?

2 Answers

I'd recommend checking out Bootstrap's npm starter project: https://github.com/twbs/bootstrap-npm-starter

It shows you exactly how to load it from npm and use it in a project.

It's better to build the CSS yourself (from the Sass files) so you can customise it and remove the components you don't need and creating a smaller CSS file.

Add this code if using server like Express

app.use(
  express.static(path.join(__dirname, "node_modules/bootstrap/dist/"))
);

Then in your head tag:

  <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
Related