O'Reilly logo

Mastering Web Application Development with Express by Alexandru Vlăduțu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Reusable Patterns for a DRY Code Base

When creating web applications with Express or Node in general, there are situations that keep repeating, and we handle them by writing the same code over and over again. In this chapter, we will create a sample application and then refactor it to eliminate the duplicated logic using the existing NPM modules.

In this chapter, we will cover the following topics:

  • Eliminating the if (err) {} pieces of code spread throughout our application
  • Using control-flow modules instead of counters and avoiding a tree-like code structure
  • Ensuring that the callback method execution only happens once
  • Extending objects in a reusable way with properties
  • Creating custom errors without having to manually define them and their ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required