Express Path to Static Files – Bower Components – 404 Error

Don’t get suckered into using the following line to reference static files like I did.

app.set(express.static(__dirname + ‘/bower_components’));

One, it will often result in 404 errors and two it statically references directory separators.

Instead use Path.

Add this in the server file.

path = require(‘path’);

And this line where appropriate.

app.use(express.static(path.join(__dirname, ‘bower_components’)));

Leave a Reply

Your email address will not be published. Required fields are marked *