 <p>The code seems to be an attempt to implement a connect middleware to serve static files. Did you try to use standard connect middleware for this purpose? Here is an example:</p> <pre><code>var connect = require('connect') var server = connect.createServer( connect.logger() , connect.static(__dirname + '/public') ) </code></pre>