Routers and controllers
So far, you have your server.js
file and a configure
module that is used to wire up all of the necessary middleware for the application. The next step is to implement proper routers and the necessary controllers.
The router is going to be a map of each of the available URL paths for the app. Every route on the server will correspond to a function in a controller. Here is what our routes table will look like for the particular application we are writing:
GET /(index) - home.index (render the homepage of the site) GET /images/image_id - image.index (render the page for a specific image) POST /images - image.create (when a user submits and uploads a new image) POST /images/image_id/like - image.like (when a user clicks the Like ...
Get Web Development with MongoDB and NodeJS - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.