Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add Bootstrap to a project in ExpressJS?

I'm developing an aplication using nodejs and the framework Express. I want to add Bootstrap to my project in local. I added this to my index <head>

<script language="javascript" src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css"/>

I found that I have to add this code to my app.js

app.use(express.static(__dirname + '../node_modules/bootstrap/dist'));

but it doesn't works too. (I have in mind the path of the Bootstrap and use '../modules...' too)

like image 947
Diego Izquierdo Dussan Avatar asked Apr 18 '18 04:04

Diego Izquierdo Dussan


1 Answers

You can try this as well, worked for me.

Install bootstrap

npm install bootstrap@3

Now in app.js file add the following code:

app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));

Use bootstrap.css in your layout or any other file

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

Make sure the path you have provided is correct.

I hope this will work :)

like image 172
Lalit Dashora Avatar answered Oct 09 '22 21:10

Lalit Dashora