CHAPTER 10

image

Abstraction

This chapter deals with code organization. Abstraction usually means breaking monolithic logic into a few pieces. Most of the techniques presented in this chapter can be applied to any Node.js code, not just Express.js code.

An Express.js app usually has a main file (app.js or server.js). You should try to keep this file as small as possible, because as it grows larger, it becomes harder to maintain. The most suitable types of code to use instead of a large main file are middleware and routes. Configuration statements can also be abstracted, but they are typically less numerous than routes, which might exceed 200 to 300. ...

Get Pro Express.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.