I'm looking to use node.js with express to create a Webserver that serves static files (as opposed to using something like Apache). This is what I have so far:
var express = require('express');
var app = express();
var http = require('http');
var path = require('path');
app.configure(function() {
app.use(express.static(path.join(__dirname, '/public')));
app.use(app.router);
});
var server = http.createServer(app);
server.listen(4001);
This works in that anything placed in the public folder can be accessed via browser. I have two questions though.
Take a look at existing implementations like ecstatic and http-server.
you can have a homepage using a /public/index.html file
you can create a 404 page by adding after app.router
app.use(function (req, res) {
res.send(404, 'File not found.')
})
or you can use res.render or whatever you'd like.