1

I've been reading all over and I can't come to a conclusion of what's happening, I would appreciate some help. First than anything, this is my setup:

-
 - views
   - partials
      header.ejs
   app.js
   ...

app.use(express.static('public/css/'));
app.use(express.static('node_modules/bootstrap/dist/css/'));

that's feeding the header page in a ejs template:

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

Now... that above works like a champ, that's how I wrote it first, but I believe that's not a clean/best practice, so I'm trying to put it like this:

Express-js can't GET my static files, why?

app.use('/static', express.static(__dirname + '/public'));

and the code they gave does not work in my case, I tried and it can't find the bootstrap or the custom css. I tried:

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

Now.. If I write this:

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

It finds the bootstrap...

I also tried the above with the coma, instead of the + and still doesn't work. Also tried this one:

How to include scripts located inside the node_modules folder?

var path = require('path');
app.use('/scripts', express.static(path.join(__dirname, 'node_modules/bootstrap/dist')));

With no good result. Could someone point me to what I'm missing/doing wrong please.

  • Why not include the bootstrap file in your template file. Your express server might not have access to the node_modules. For your `static` route, try: `app.use('/static', express.static(path.join(__dirname, 'public')))` – HackAfro Jun 29 '18 at 22:22
  • Hi, thanks for the help. It does have access because if I write: app.use(''", express.static(path.join(__dirname + 'node_modules/bootstrap/dist/css/'))); it would serve the bootstrap folder. And for now I'm just trying to learn it this way, eventually the css will be written from scratch –  Jun 29 '18 at 22:31

0 Answers0