Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include bootstrap file in my ejs files?

So i have installed bootstrap using npm -bootstrap@3 but when i am trying to include bootstrap.min.css file from node_modules in my application, it shows this error in my console :

error message

enter image description here

In the network tab it shows

404 not found on the bootstrap source.

Below are some images on my project structue:

project folder structure

enter image description here

ejs code to include bootstrap file

enter image description here

Whats the issue here?

like image 337
D_S_X Avatar asked Feb 02 '26 03:02

D_S_X


1 Answers

I got the same issue following this tutorial. You can solve this by express.static built-in middleware function.

  1. Create a directory named public
  2. Add following code to your app.js file

    app.use(express.static('public'))

  3. Now you can place your bootstrap files in this directory(or subdirectory) and link them relative to public directory.

You can find more info here. https://expressjs.com/en/starter/static-files.html

like image 86
Kavinda Athapaththu Avatar answered Feb 03 '26 15:02

Kavinda Athapaththu