Skip to content

Instantly share code, notes, and snippets.

View flopywood's full-sized avatar

Flor flopywood

  • Buenos Aires, Argentina
View GitHub Profile
@flopywood
flopywood / error.js
Created November 9, 2016 14:09 — forked from primaryobjects/error.js
Redirect 404 errors to a static web page in node.js Express.
var fs = require('fs');
// In your app.js, include a route handler for all other routes (*) to go to error404.
// app.get('*', error.error404);
exports.error404 = function(req, res) {
if (req.accepts('html')) {
// Respond with html page.
fs.readFile(__dirname + '/../../public/404/index.html', 'utf-8', function(err, page) {
res.writeHead(404, {'Content-Type': 'text/html'});
res.write(page);