i'm building a bookstore app with expressjs and using mongodb to store data i have a database of books i want to display to my index.jade but i keep running into an infinite loop
extends layout
block content
.content
each book in books
.book
img(src="/images/dumbk.png", width="150px", height="200px")
h4.book-title #{book.title}
h6.book-dtls Price: #{book.price} SDG
p.book-desc #{book.description}
a.btn.btn-primary.view(href="/books/details/1") View Book
and this is my index.js
var express = require('express');
var router = express.Router();
var Book = require('../models/bookModel');
/* GET home page. */
router.get('/', /*ensureAuthenticated, */function(req, res, next) {
Book.find({}, function (err, books) {
if (err) {console.log(err);}
var model = {books: books}
console.log(model);
res.render('index', /*{books: books},*/ { title: 'Members' });
});
});
after logging model it logged all the books in my database but it does not render them and keeps running an infinite loop when i tried to log a book title by using book.title in the jade file
-console.log(book.title)
result was undefined
so am sure that the error is in the loop and the formatting
when i log the model the output is
[ { _id: the id, title: "book title", author: "author", price: "10", description: "a book description", stock: "5", cover: "dumbk.png" } ]