Thursday, 5 January 2017

connect module

for adding connect modules in the project
on colsole type
npm install connect


use of connect module
1-> first use
/** * Created by deepak gautam on 06-01-2017. */
//here in this code we are showing how we can use 
//2  functions for response 
// one aftre another 
// if comment next() , than 2nd function will be never calledvar connect = require('connect');
var http=require('http');
var app=connect();
function  dofirst(request,response,next)
{

     console.log("this is do first");
     next();

}
function  dosecond(request,response,next)
{

    console.log("this is do second");
    next();

}
app.use(dofirst);
app.use(dosecond);

http.createServer(app).listen(8888);


2-> second use

//if   we need to call different functions accordig to url than also we can use 
// connect.

/** * Created by deepak gautam on 06-01-2017. */
var connect = require('connect');
var http=require('http');
var app=connect();


function profile_page (request,respose) {
     console.log("this is profile page ");

}
function details_page (request,respose) {
    console.log("this is details page ");

}
app.use('/profile',profile_page);
app.use('/details',details_page);
http.createServer(app).listen(8888);

No comments:

Post a Comment