Skip to main content

Working with Middleware

  • Chapter
  • First Online:
Pro Express.js
  • 1680 Accesses

Abstract

Middleware is an amazingly useful pattern that allows developers to reuse code within their applications and even share it with others in the form of NPM modules. The essential definition of middleware is a function with three arguments: request (or req), response (res), and next. If you’re writing your own middleware, you can use arbitrary names for arguments, but it’s better to stick to the common naming convention. Here’s an example of how to define your own middleware:

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 54.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 69.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

  2. 2.

    http://andrewkelley.me/post/do-not-use-bodyparser-with-express-js.html

  3. 3.

    https://www.npmjs.org/package/busboy

  4. 4.

    https://www.npmjs.org/package/formidable

  5. 5.

    https://www.npmjs.org/package/multiparty

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2014 Azat Mardan

About this chapter

Cite this chapter

Mardan, A. (2014). Working with Middleware. In: Pro Express.js. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0037-7_4

Download citation

Publish with us

Policies and ethics