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