“Ekspres data lulus antar middleware” Kode Jawaban

Ekspres data lulus antar 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

Ekspres data lulus antar 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

Jawaban yang mirip dengan “Ekspres data lulus antar middleware”

Pertanyaan yang mirip dengan “Ekspres data lulus antar middleware”

Lebih banyak jawaban terkait untuk “Ekspres data lulus antar middleware” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya