kyr
kyr

Reputation: 221

Express.js static serving not working

I'm trying to apply a bootstrap theme to a file generated by Jade, but it says it cannot GET the file.

Main JS file:

var express = require('express')
app = express();

app.set('views', __dirname + '/templates');

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

app.get('/', function(req, res){res.render('index.jade', {title: 'stuff'});});

var port = Number(process.env.PORT || 5000);
app.listen(port, function () {
  console.log('Listening on ' + port);
});

index.jade:

link(rel='stylesheet', href='public/lumen.min.css')
h1 
   a(href='http://example.com') test
p this is a test

Any solutions on this?

Upvotes: 1

Views: 2107

Answers (1)

SomeKittens
SomeKittens

Reputation: 39522

href='public/lumen.min.css' is trying to access a file located at __dirname + public/public/lumen.min.css (note the double public). Change that line to:

link(re='stylesheet', href='lumen.min.css')

You don't need to prepend the public directory to your src/href attributes, express is smart enough to figure that out.

For more examples of using express.static, check out the docs.

Upvotes: 5

Related Questions