“Express Pass Data entre middleware” Réponses codées

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

Réponses similaires à “Express Pass Data entre middleware”

Questions similaires à “Express Pass Data entre middleware”

Plus de réponses similaires à “Express Pass Data entre middleware” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code