I cannot seem to get express 3.x to server up static files in my public directory. They all request end with 404.
var express = require('express')
, engine = require('ejs')
, app = express();
app.configure(function () {
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
});
app.get('/', function(req, res) {
res.render('test.ejs')
});
app.listen(3000);
My test.ejs is had references to the js files that look like so:
<script type="text/javascript" src="js/testscene.js"></script>
I must be overlooking something simple. I have the following folder structure:
project
-public
-js
testscene.js
-views ]
Can someone tell me what I've missed?
Update
I actually created a new project and copied my script into this new project and it works?! I guess Ill just have to close this as some sort of localized weirdness. Thanks for all of your time.
__dirname is the directory where the current .js file resides. Your filesystem ascii art diagram omits this essential piece of the puzzle. If your first code snippet lives at project/server.js, for example, then that is correct. I think then loading http://localhost:3000 in your browser should properly find the js/testscene.js file. However, using relative URIs is usually a bad idea unless you really are sure you want/need it, so for the sake of sanity, change that to be src="/js/testscene.js".