You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Really good job, Danushka! I really like how explanatory your comments are. Makes it easy to understand your code and overall it looks really good! 🙂 The only things I can comment on are:
Your architecture:
To make the code more easy to follow and update you could break out a lot of stuff from your server.js. For example, you could follow the MVC (Model–View–Controller) architecture. I’m sure you’ve heard about it. 🙂 Following that architecture you could put your mongoose models in a folder called “models”, your request handling in a folder called “controllers” and your routes in a “routes” folder. This way, server.js is clean (just setup + wiring), while logic and data handling live in their own files.
Route order:
I also read something about organizing your more specific routes first, and your generic /:id routes last inside each route file. This, because the order matters in Express. If you have a dynamic route like /:id, it can accidentally “catch” other requests if placed above more specific routes. So I guess that’s another reason it’s better to separate the routes into different files.
The reason will be displayed to describe this comment to others. Learn more.
✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(https://js-project-api-zqp9.onrender.com/)