Index - retrieving an image model

The primary responsibility of the index function in our image controller is to retrieve the details for a single, specific image, and display that via its viewModel. In addition to the details for the actual image, the comments for an image are also displayed on the page in the form of a list. Whenever an image is viewed, we also need to update the view count for the image and increment it by one.

Begin by editing the controllers/image.js file and updating the list of required modules at the top, to include our models module:

const fs = require('fs'), 
path = require('path'), 
sidebar = require('../helpers/sidebar'), 
Models = require('../models');

We also want to strip viewModel down to its most basic form, ...

Get Web Development with MongoDB and Node - Third 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.