As mentioned in my previous post, I learnt Node.js and Restify through the Udemy course titled "A Simple Node.js/Mongo/Restify API in Less Than 3 Hours" by Jim Hlad. I made a copy of the Node.js API sample app that was taught in the course and called it Cwitiq. This app would manage reviews instead of users.
A rough diagram of the code is depicted below. On the right, the directories for the various layers are shown.
A rough diagram of the code is depicted below. On the right, the directories for the various layers are shown.
- include (require) the restify, restify plugins, validator and mongoose modules
- create a restify server using the createServer function
- the config directory has the db connection and helper functions to provide responses (output, error etc.)
- the models directory has the schema and model for storing the reviews in MongoDB using Mongoose
- the business logic is in the reviewController that is present in the controllers directory along with setupController that utilizes Restify features to control APIs - authorization, whitelisting, throttling
I have been using this layout and code organization while creating other apps in Node.js.
No comments :
Post a Comment
Leave a Comment...