I'm trying to redirect to an html page when a 404 error is thrown. I have a folder titled: 404 in my public folder. Here is the code in the index.js:
var express = require('express');
var app = express();
app.use(express.static(__dirname + "/public"));
app.route('/me').get(function(req, res){
res.sendFile(__dirname+'/public/html/contacts.html')
})
app.use(function(req, res, next){
// res.type('txt').send('Not found');
// res.status(404).end('error');
if (req.accepts('html')) {
res.render('404', { url: req.url });
return;
}
});
var server = app.listen(8000, function(){
console.log("Server is happening %s", server.address().port);
});
But I get the following error:
Error: No default engine was specified and no extension was provided. at new View (/home/pi/server/node_modules/express/lib/view.js:62:11) at EventEmitter.render (/home/pi/server/node_modules/express/lib/application.js:569:12) at ServerResponse.render (/home/pi/server/node_modules/express/lib/response.js:961:7) at /home/pi/server/index.js:19:9 at Layer.handle [as handle_request] (/home/pi/server/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/pi/server/node_modules/express/lib/router/index.js:312:13) at /home/pi/server/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/home/pi/server/node_modules/express/lib/router/index.js:330:12) at next (/home/pi/server/node_modules/express/lib/router/index.js:271:10) at SendStream.error (/home/pi/server/node_modules/express/node_modules/serve-static/index.js:120:7) Error: No default engine was specified and no extension was provided. at new View (/home/pi/server/node_modules/express/lib/view.js:62:11) at EventEmitter.render (/home/pi/server/node_modules/express/lib/application.js:569:12) at ServerResponse.render (/home/pi/server/node_modules/express/lib/response.js:961:7) at /home/pi/server/index.js:19:9 at Layer.handle [as handle_request] (/home/pi/server/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/pi/server/node_modules/express/lib/router/index.js:312:13) at /home/pi/server/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/home/pi/server/node_modules/express/lib/router/index.js:330:12) at next (/home/pi/server/node_modules/express/lib/router/index.js:271:10) at SendStream.error (/home/pi/server/node_modules/express/node_modules/serve-static/index.js:120:7)