Node.js connect create handler by path

Description

Node.js connect create handler by path


//Configurable middleware creator
function greeter(message){
    return function(req,res,next){
        res.end(message);//  w  w w.j a  v a2s.c o m
    };
}

var helloWorldGreeter = greeter('Hello world!');
var heyThereGreeter = greeter('Hey there!');


var connect = require('connect');

connect()
    .use('/hello',helloWorldGreeter)
    .use('/hey',heyThereGreeter)
    .listen(3000);
console.log('server is running on port 3000');



PreviousNext

Related