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, ...