Updating the home controller

If you take a look at our current home controller (controllers/home.js), you can see that the index function barely has any code in it whatsoever:

res.render('index');

The first thing we want to do is build a basic view model using sample data so that we can see our view model at work. Replace that single res.render call with the following updated code:

var viewModel = { images: [ { uniqueId: 1, title: 'Sample Image 1', description: '', filename: 'sample1.jpg', views: 0, likes: 0, timestamp: Date.now }, { uniqueId: 2, title: 'Sample Image 2', description: '', filename: 'sample2.jpg', views: 0, likes: 0, timestamp: Date.now }, { uniqueId: 3, title: 'Sample Image 3', description: '', filename: 'sample3.jpg', views: 0, likes: ...

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.