Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Creating Custom Middleware | Section
Building APIs with Express.js

bookCreating Custom Middleware

メニューを表示するにはスワイプしてください

You can create your own middleware to control how requests are processed.

A middleware function receives three arguments: req, res, and next.

const logger = (req, res, next) => {
  console.log(req.method, req.url);
  next();
};

app.use(logger);

This middleware logs the request method and URL for every incoming request.

When a request comes in:

  • Middleware runs first;
  • It performs its logic;
  • It calls next() to continue.

If next() is not called, the request will not move forward.

Custom middleware is useful for adding shared behavior across your application, such as logging or validation.

question mark

What happens if next() is not called in middleware?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  11

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  11
some-alt