---
title: "Discussion on \"Making your own Express Middleware\" | Hashnode"
description: "Discussion on \"Making your own Express Middleware\". Express is a common way to display static routes to a user. It is even more commonly used to create APIs for Node.JS. In Express, it's easy to define a URL, and what will happen at that URL. We can also define middleware, which runs before the final ..."
url: "https://hashnode.com/posts/making-your-own-express-middleware/62af5ce6d8afe74aa51fd883"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Making your own Express Middleware](https://fjolt.hashnode.dev/making-your-own-express-middleware?utm_source=hashnode&utm_medium=feed)

Express is a common way to display static routes to a user. It is even more commonly used to create APIs for Node.JS. In Express, it's easy to define a URL, and what will happen at that URL. We can also define middleware, which runs before the final ...

Jun 19, 2022 · 4 min read · fjolt.hashnode.dev  
Read the article

-   [#web-development](https://hashnode.com/tag/web-development)
-   [#tutorial](https://hashnode.com/tag/tutorial)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Johnny](https://hashnode.com/@smpnjn)

@smpnjn

  
[View profile](https://hashnode.com/@smpnjn)

Product, Engineering, Web

## Responses 1

Markdown supported · ⌘↵ to post

[Elvis Van](https://hashnode.com/@elvisvan)

[Jun 20, 2022](https://hashnode.com/posts/making-your-own-express-middleware/62af5ce6d8afe74aa51fd883/comment/62afc7370924134a8048af49)

Why would we need middleware to pass data through? wouldn't the server-client connection be faster if we just let data flows to the end location?

[Johnny](https://hashnode.com/@smpnjn)

[Jun 20, 2022](https://hashnode.com/posts/making-your-own-express-middleware/62af5ce6d8afe74aa51fd883/comment/62afc7370924134a8048af49#reply-62b01630d8afe74aa51fee08)

It’s an example. As another example, using a real life middleware, if you use express-session, using ‘app.use(session({}))’ it sets up a session and then defines req.session to store session data on all your routes. That means you can access this property (‘req.session’) on all routes rather than having it have to be defined each time.

In terms of speed, the example I used will only likely add in the magnitude of 0.01ms to the request. More complex logic will add more time but for raw JS (no db calls, etc), I wouldn’t expect it to add very much extra time to load at all.
