0

I am new in nodejs and i am using "expressjs" framework,And i am trying to show simple static page using "pug" extension but "css" file is not loading/working Here is my file strcture

demo(Main Project/root)
    index(Main file)
    views
        public
            views
                dashboard
                    style.css

And here is index.js code

var express = require('express')
var app = express()
//app.use("/styles", express.static(__dirname + '/styles'));
var path = require('path');

app.set('views', path.join(__dirname, './views'));
app.set('view engine', 'pug');
app.use(express.static(path.join(__dirname, 'public')));


app.get('/first_template', function(req, res){
   res.render('index');
});

app.listen(3000)

Here is my index.pug code

html
      head
        title Dashboard
        link(rel='stylesheet', href='/views/dashboard/style.css')
      body
      p Hi!

How can i add "style.css" to index.pug ? Where i am wrong ?

Ritika
  • 1
  • 1
    Does this answer your question? [pugjs(jade) template engine loading css file](https://stackoverflow.com/questions/7956038/pugjsjade-template-engine-loading-css-file) – Anonymous User Sep 09 '21 at 04:53
  • Your directory structure is real weird. You should have the `views` folder (the folder for pug files) and the `public` folder in the same level, so that pug source files can't be accidentally leaked. With your current structure, it should be `app.use(express.static(path.join(__dirname, "views/public")));`. – Old Geezer Sep 18 '21 at 14:48

0 Answers0