Using res.render to Display Templates in Express
📖 Scenario: You are building a simple web server using Express.js. You want to show a welcome page to users using a template.
🎯 Goal: Create an Express app that uses res.render to display a template called welcome with a message.
📋 What You'll Learn
Create an Express app instance called
appSet the view engine to
pugCreate a route for
/ that uses res.render to show the welcome templatePass a variable called
message with the value 'Hello, visitor!' to the template💡 Why This Matters
🌍 Real World
Web servers often use templates to create dynamic HTML pages that show different content depending on the user or situation.
💼 Career
Knowing how to use res.render and templates is essential for backend web developers working with Express.js to build user-friendly websites.
Progress0 / 4 steps