Author detail page

The author detail page needs to display the information about the specified Author, identified using their (automatically generated) _id field value, along with a list of all the Book objects associated with that Author.


Open /controllers/authorController.js.

Add the following lines to the top of the file to import the async and Book modules (these are needed for our author detail page).

const async = require("async");
const Book = require("../models/book");

Find the exported author_detail() controller method and replace it with the following code.

// Display detail page for a specific Author.
exports.author_detail = (req, res, next) => {
      author(callback) {
      authors_books(callback) {
        Book.find({ author: }, "title summary").exec(callback);
    (err, results) => {
      if (err) {
        // Error in API usage.
        return next(err);
      if ( == null) {
        // No results.
        const err = new Error("Author not found");
        err.status = 404;
        return next(err);
      // Successful, so render.
      res.render("author_detail", {
        title: "Author Detail",
        author_books: results.authors_books,

The method uses async.parallel() to query the Author and their associated Book instances in parallel, with the callback rendering the page when (if) both requests complete successfully. The approach is exactly the same as described for the Genre detail page above.


Create /views/author_detail.pug and copy in the following text.

extends layout

block content

  h1 Author: #{}
  p #{author.date_of_birth} - #{author.date_of_death}


    h4 Books

      each book in author_books
          a(href=book.url) #{book.title}
        dd #{book.summary}

        p This author has no books.

Everything in this template has been demonstrated in previous sections.

What does it look like?

Run the application and open your browser to http://localhost:3000/. Select the All Authors link, then select one of the authors. If everything is set up correctly, your site should look something like the following screenshot.

Author Detail Page - Express Local Library site

Note: The appearance of the author lifespan dates is ugly! We'll address that in the final challenge in this article.

Next steps