Chapter 7. Modularizing Our Code
In the previous chapter, we followed a TDD workflow and implemented the first endpoint of our API—the Create User endpoint. We wrote our End-to-End (E2E) tests in Gherkin, ran them using the Cucumber test runner, and used them to drive development. Everything works, but all the code is contained within a single, monolithic file (src/index.js
); this is not modular and makes our project hard to maintain, especially as we add more endpoints. Therefore, in this chapter, we will be separating our application code into smaller modules. This will allow us to write unit and integration tests for them in Chapter 8, Writing Unit/Integration Tests.
By following this chapter, you will be able to do the following:
- Break down large blocks of code into smaller modules
- Define and validate JavaScript objects with JSON Schema and Ajv