Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


jang walia
jang walia
7,717 Points

uploading image in pug template

I HAVE STARTED EXPRESS BASIC COURSE AND I AM STUCK AT A POINT WHERE THE OBJECT ASSIGN IN PUG FILE IS NOT SHOWING THE IMAGE.AND ITS GIVING ERROR,THE HOME PAGE IS SHOWING THE IMAGES BUT PRODUCT.PUG IS NOT. IF ANY ONE COULD HELP...THNXXXX MY CODE IS BELOW javascript file: const express = require('express'); const product = require('../../JSON FOLDER/product.json'); var app = express(); app.set('view engine','pug'); app.use(express.static('../../JSON FOLDER')); app.get('/',(req,res)=>{ res.render('Home',{product}); }) app.get('/product/:id',(req,res)=>{ const productId = req.params.id; const item = product.find( element=>element.id === productId ); if(item){ res.render('product',{item}); } else{ res.sendStatus(404); } }) console.log('The server is running at port 3000'); app.listen(3000); PRODUCT.PUG: doctype html html(lang="eng") head title Product Info body header h1 Home Decor section#Myproduct img(src=item.image style='width:300px;height:300px;') footer p Copyright @ homeshopping.com

PRODUCT.JSON: [ { "image" : "image1.png", "id":"001", "cost": "10.00" }, { "image" : "image2.png", "id":"002", "cost": "10.00" } ]