0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Express入門】ミドルウェアとは?

Posted at

はじめに ミドルウェアとは?

・クライアントからのリクエストに対してのフィルター
例)認証など

実践

server.js
const express = require("express");
const app = express();

// ミドルウェア関数
const myLogger = function (req, res, next) {
    console.log(req.originalUrl);
    next();
};

// ミドルウェアの実行
app.use(myLogger);

注意点:ミドルウェアを使う際には、ルーティングの一番前に記述しないと、ミドルウェアが起動しない

さいごに

・ログイン認証などに使えそう!

参考記事

参考動画

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?