Created
July 21, 2012 01:23
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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