Skip to main content

Working with Middleware

  • Chapter
  • First Online:

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.

Buying options

eBook
USD   19.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   27.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

Learn about 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: Express.js Deep API Reference. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0781-9_2

Download citation

Publish with us

Policies and ethics