Just starting off with node.js and following Node Cookbook but I am stuck on URL routing part.
here is the code from the book itself:
var http = require('http');
var path = require('path');
var pages = [
{route: '', output: 'Woohoo!'},
{route: 'about', output: 'A simple routing with Node example'},
{route: 'another page', output: function() {return 'Here\'s '+this.route;}},
];
http.createServer(function (request, response) {
var lookup = path.basename(decodeURI(request.url));
pages.forEach(function(page) {
if (page.route === lookup) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end(typeof page.output === 'function'? page.output() : page.output);
}
});
if (!response.finished) { // couldn't find any documentation for response.finished
response.writeHead(404);
response.end('Page Not Found!');
}
}).listen(8080);
console.log('Server started');
Though code runs without any errors and seems it does what they meant but looking to the node.js documetation and searching on Google for response.finished
doesn't yields any result.
and here is the quote from the book in context of explaining response.finished
Could you please explain what the actually meant by that quotation or any citation for response.finished
.