I\'m currently experiencing some minor problems with serving static files through expressJs.
My directory structure is as following:
__dirname
doesn't have a trailing slash, so __dirname + '../'
results in DIRNAME../
(which isn't valid).
Instead, use:
__dirname + '/../public'
^ extra slash
You should use path.join instead of manually concatening path components. It uses path.normalize, which resolves .
and ..
, handles multiple or trailing slashes, and uses the appropriate file separator for your platform (see: path.sep).
For example,
var path = require('path');
var express = require('express');
var app = express();
app.use(express.static(path.join(__dirname, '../public')));