Skip to content

Instantly share code, notes, and snippets.

@juanpujol
Created July 21, 2012 01:23
Show Gist options
  • Save juanpujol/3154152 to your computer and use it in GitHub Desktop.
Save juanpujol/3154152 to your computer and use it in GitHub Desktop.
Simple Node.js Express app that renders every file in the /public directory.
// Install express with: npm install express.
var express = require('express'),
app = express();
// Before any request console.log all requests.
app.use(function(req, res, next){
console.log('Intercepted request from: ' + req.url);
next();
});
// Serve static files from public direcory.
app.use(express.static(__dirname + '/public'));
// 404 Page not found.
app.use(function(req, res, next){
res.send('Error 404. Page not found', 404);
});
app.listen(process.env.PORT || 4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment