Tag Archives: controllers in Node.js

01 Project – Node.js / Express / MongoDB – Part 13 – Creating the controller and the view model for the image page

The controller for the image will handle uploading and saving of the image files via the form on the homepage.

In the image controller we are going to build a view model for a single image. It will render a detailed view of an image (including the comments for the image).

Continue reading

Node.js | Controllers and View Models

Controllers

A controller renders a response to the client. It generates the data necessary for a page to appear complete.

A controller manipulates models and initiates the view render process with the data received from the
corresponding models. A controller is a function. A controller function is executed when its corresponding route is accessed.

Continue reading

01 Project – Node.js / Express / MongoDB – Part 11 – Rendering the views

None of these views we have created so far will do anything unless we make a few modifications to our controllers to get our views to render properly.

Open /controllers/home.js and update the contents to look identical to the code shown below:

module.exports = {
  index: function(req, res) {
    res.render('index');
  }
};

Continue reading