nodejs middlewares | nodejs tutorials

 with use we  can use middleware


in below 

code

middleware- whenever before process actualt request - middlewre acts as mediator - if it passes

whenever reaches home url

it calls log and hello function 

because it ats as middleare in this

when log call bcak function it printes log

when hello function it prints hello

 


next means -  go back to api , after log , calls next middleware

const express = require('express');
const app = express();

app.get("/", log, hello);

function log(req, res, next)
{
console.log("log started");
next();
}
function hello(req, res, next)
{
console.log("hello started");
next();
}

app.listen(8081,
function () {
console.log("server started");
});

No comments:

Post a Comment

React -1 ( react with ravenndra kanchi)

 react with tool chanis 45 to 50 sessions core  after 50 sessions -> some tooll chains == react with type script mern stackaplication in ...