Learn Express: Middleware

Learn about how to use Express middleware to improve your API's code quality and readability

Start[missing "en.views.course_landing_page.learn-express.course_illustration" translation]
  1. 1

    Writing code is a creative process. Programmers will be quick to differ in opinion on whether the solution to a problem should be implemented in one way or another — citing tradeoffs in algor...

  2. 2

    Beyond labeling, good code will leverage the strength of its programming language to avoid performing the same tasks Take a look at the following code: [...] [...] Your number plus 5 is ${five...

  3. 3

    By now you may have noticed that our efforts to not repeat ourselves have resulted in us putting the same function call over and over throughout our code. Isn't that somewhat contradictory? You wou...

  4. 4

    It seems like our middleware was successful — it logged out . But then the response stopped there! What happened? We mentioned that most of Express's functionality is chaining middleware. Th...

  5. 5

    Recall the function signature of an Express middleware, i.e., [...] . You might recognize this signature as being the very same that we've used for Express routes in the past. Well there's a perfe...

  6. 6

    Now that we've managed to refactor our duplicate code into middleware functions, we should be noticing that our code contains much less repetition than before. Unfortunately, we still have duplicat...

  7. 7

    We've experienced writing middleware that performs its function and hands off the request and response objects to the next function in the stack, but why exactly do we have to write [...] at the ...

  8. 8

    We learned that [...] takes a path parameter, but we never fully investigated what that [...] parameter could be. Let's take another look at the Express documentation for [...] : "argument:...

  9. 9

    Recall that middleware is just a function with a specific signature, namely [...] . We have, for the most part, been using anonymous function definitions for this because our middleware has only b...

  10. 10

    Knowing how to write middleware, we should now feel inspired to solve all the problems that come at us by writing code. It's encouraging to know how to fix an issue. If we find a solution we don't ...

  11. 11

    With software we've personally written, invocation is a simple process. We already know what the code does, what it expects, and may have some notion how things could go wrong. Losing this intuitio...

  12. 12

    Being able to use open-source middleware can certainly make our jobs as programmers a lot easier. Not only does it prevent us from having to write the same code every time we want to accomplish a c...

  13. 13

    We're almost finished with our Code Quality Checklist, there's just one last problem to fix! When an error is thrown somewhere in our code, we want to be able to communicate that there was a proble...

  14. 14

    While it's good to know how to write error-handling middleware, it's a natural curiosity that causes us to ask "isn't error-handling a common task? Has someone written middleware that performs it f...

  15. 15

    We've accomplished a lot! We learned what middleware is and we've used it to write cleaner, readable, adaptable, and maintainable code. We've written functions that are context aware and can have o...

  1. 1

    When building interfaces with Express, we will run into the pattern of expecting certain information in a requested URL and using that information to identify the data that is being requested. To g...

  2. 2

    Express, luckily, is mindful of the pain-point of replicated parameter-matching code and has a method specifically for this issue. When a specific parameter is present in a route, we can write a fu...

  3. 3

    Complexity is all around us. Buildings are made from bricks and many droplets of water make a cloud. When we want to create something complex in software, we model out our base components and use _...

  4. 4

    [...] is a powerful tool that we can use to keep our code from repeating core functionality through routes. This is a pattern we want to frequently follow: identify multiple pieces of code that a...

  1. 1

    Code Challenge

  2. 2

    Code Challenge

  3. 3

    Code Challenge

  4. 4

    Code Challenge

  5. 5

    Code Challenge

  6. 6

    Code Challenge

  7. 7

    Code Challenge

  8. 8

    Code Challenge

  9. 9

    Code Challenge

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Learn Express: Middleware

Start[missing "en.views.course_landing_page.learn-express.course_illustration" translation]