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

JavaScript Express Basics Using Templates with Express Express’s Response.render Method

Kevin Ohlsson
Kevin Ohlsson
4,559 Points

How does prompt variable in CARD.PUG know were the variable resides?

Hello

I dont understand Andrews (author) explaination of how the prompt variable in the pug template card.pug finds its variable.

https://expressjs.com/en/4x/api.html#res.render Documentation says: "The view argument is a string that is the file path of the view file to render."

app.get('/cards', (req, res) => { // creates url /CARDS
    res.render('card', {prompt: "what the"}); // what does CARD mean here? 
})

1 Answer

Kevin Ohlsson
Kevin Ohlsson
4,559 Points

i think i get it...

app.get('/cards', (req, res) => { // creates url /CARDS
    res.render('card', {prompt: "what the"}); // uses the pug file card and bridges app.js prompt with its call in the pug template
})