I designed several portals for an educational institution in Toronto a few years ago.
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:
Import the controller class and create a route for the controller's method
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.
Loads all the controllers and routes when the server starts up
Generic way to load the controllers and the routes
A single controller encapsulating all the routes and methods - can call into the services and repository layers and implement interfaces as in any OO architecture
His project can be found here for people interested in it to research more:
This is it, folks! Enjoy the tip and be happy!
Comments