Skip to content

Express

Billy Bunn edited this page Mar 26, 2019 · 3 revisions

Express is a routing and middleware framework. What does that even mean?

Express routing

Based on a reading of the Express documentation.

When we talk about routing, we're referring to how an app responds to certain endpoints and HTTP request methods (GET, POST, etc.). Routes have handler functions that fire when the app responds to a request.

The Express documentation explains that routes look like this:

app.METHOD(PATH, HANDLER)

Where:

  • app is an instance of express.
  • METHOD is an HTTP request method, in lowercase.
  • PATH is a path on the server.
  • HANDLER is the function executed when the route is matched

There's a rout method for each HTTP method (and more). See here for all the methods.

Express middleware

Based on a reading of the Express documentation.

Middleware refers to functions that can access the request, the response, and the next middleware function in an app's request-response cycle. An app that uses Express is basically a bunch of middleware functions that are called on certain routes and/or call each other in a series.

Middleware functions can do a lot. They can run any piece of code you want, make changes to the requests & responses, or call another function (officially called next middleware function).

Since this definition is so broad, it's helpful to define certain times of middleware based on their function and where they come from. Here's the list from the Express documenation:

  • Application-level
  • Router-level
  • Error-handling
  • Built-in
  • Third-party

Resources

Read

Watch

Skim

Bookmark

Clone this wiki locally