0
0
Expressframework~5 mins

res.render for templates in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does res.render() do in Express?

res.render() tells Express to use a template engine to create HTML from a template file and send it as a response to the browser.

Click to reveal answer
beginner
How do you pass data to a template using res.render()?

You pass an object as the second argument to res.render(). The object contains key-value pairs that the template can use to show dynamic content.

Click to reveal answer
beginner
What is the role of a template engine in res.render()?

A template engine takes a template file and data, then combines them to create HTML. res.render() uses this engine to build the final page sent to the user.

Click to reveal answer
beginner
What happens if you call res.render('index') without passing data?

Express renders the index template with no extra data. The template will show static content or default values if coded that way.

Click to reveal answer
intermediate
Can res.render() be used to render templates other than HTML?

Yes, depending on the template engine, res.render() can generate other text formats like XML or plain text, but HTML is the most common.

Click to reveal answer
What is the first argument to res.render()?
AThe name of the template file
BThe data object
CThe HTTP status code
DThe response headers
How do you send dynamic data to a template in Express?
ABy setting HTTP headers
BBy calling <code>res.send()</code> before <code>res.render()</code>
CBy passing an object as the second argument to <code>res.render()</code>
DBy modifying the URL query string
Which of these is NOT a common template engine used with Express?
AEJS
BReactDOM
CHandlebars
DPug
What does res.render() send back to the client?
ARaw template file
BJSON data
CJavaScript code
DRendered HTML content
If you forget to set a template engine in Express, what happens when you call res.render()?
AExpress throws an error
BExpress sends the template file as plain text
CExpress ignores the call
DExpress sends a 404 response
Explain how res.render() works in Express and how you use it to send a web page.
Think about how Express combines a template and data to create a page.
You got /4 concepts.
    Describe how you pass dynamic content to a template using res.render() and why this is useful.
    Consider how websites show different info to different users.
    You got /4 concepts.