Refining Node.js Architecture: Elegant Separation of Routers and Controllers
A few years ago, I designed several portals for an educational institution in Toronto.
The portals were developed with Angular 7 for the front end and utilized a REST API with Express and Node.js on the back end. They communicated with a database and were integrated with Azure B2C Single Sign-On within the Azure Cloud.
Recently, I decided to rewrite a similar application using the latest Angular version (18) and to document every step of the design, coding, and deployment process for a book I am planning to author.
While beginning this project, I encountered a tip that I believe is worth sharing with you. This tip relates to the implementation of routes and controllers for a Node.js REST API server.
A popular method for separating routes and controllers in a Node.js REST API server is outlined in several online articles, such as the one mentioned below:
Dan Wahlin presents a more elegant approach in his Pluralsight course, 'Integrating Angular 11 with Node.js RESTful Services', where routes are automatically created upon application startup and defined within each controller.
His project can be found here for people interested to research it more:
This is it, folks! Enjoy the tip and be happy!