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.
- How do I make it so that node.js will provide a 404 error when a user tries to access a non-existent file?
- How would I then select my homepage?