“Express Pass Data entre middleware” Respostas de código

Express Pass Data entre middleware

function middleware1(req, res, next) {
  // Set data
  req.dataFromMiddleware1 = "Data of Middleware 1";
  // Go to next middleware
  next();
}
  
function middleware2(req, res, next) {
  console.log("We are in Middleware 2.");
  // Get Data of Middleware1
  console.log(req.dataFromMiddleware1);
  // Go to next middleware
  next();
}
  
// Handling Get Request '/'
app.get("/", middleware1, middleware2, (req, res) => {
  return res.send(req.dataFromMiddleware1);
});
KostasX

Express Pass Data entre middleware

function middleware1(req, res, next) {
  // Set data
  req.dataFromMiddleware1 = "Data of Middleware 1";
  // Go to next middleware
  next();
}
  
function middleware2(req, res, next) {
  console.log("We are in Middleware 2.");
  // Get Data of Middleware1
  console.log(req.dataFromMiddleware1);
  // Go to next middleware
  next();
}
  
// Handling Get Request '/'
app.get("/", middleware1, middleware2, (req, res) => {
  return res.send(req.dataFromMiddleware1);
});
KostasX

Respostas semelhantes a “Express Pass Data entre middleware”

Perguntas semelhantes a “Express Pass Data entre middleware”

Mais respostas relacionadas para “Express Pass Data entre middleware” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código