# What is Middleware? — Express.js Fundamentals: Routing, Middleware and APIs

Source: https://www.skillbyai.com/en/expressjs/ex-middleware-concept

> Understand middleware as functions that inspect requests and call next, and how order affects behaviour.

## req, res, next

A **middleware** is a function `(req, res, next) => {}` that can inspect or modify the request/response, then call `next()` to pass control along — or end the response itself.

## An airport security line

Each checkpoint (bag scan, ID check, boarding pass) inspects you and waves you through with **next()** — or stops you right there if something's wrong.

## A logging middleware

`app.use` runs a middleware for every request, in the order it was registered.

```javascript
app.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});
```
