change the code in your models/product.js
static findById(id, cb) {
getProductsFromFile(products => {
const product = products.find(p => p.id === id);
cb(product === undefined ? "Product details" : product.title, product);
});
}
by replacing
cb(product)
with
cb(product === undefined ? "Product details" : product.title, product);
then adjust your shop.js controller by changing
exports.getProduct=(req,res,next)=>{
const prodId=req.params.productId;
Product.findById(prodId,product=>{
res.render('shop/product-detail.ejs',{
product:product,
pageTitle: product.title,
path:'/products'
});
});
};
to
exports.getProduct = (req, res, next) => {
const prodId = req.params.productId;
Product.findById(prodId, (title,product) => {
res.render('shop/product-detail', {
product: product,
pageTitle: title,
path: '/products'
});
});
};