Server-Rendered Views
5 min read
Module Overview
What You’ll Learn
- Explain what a view engine is and why Express supports them
- Render dynamic HTML pages with EJS
- Decide when a server-rendered view makes more sense than a JSON API
💡 Why this module matters: Not every backend exists purely to serve JSON to a separate frontend. Admin panels, internal tools, and plenty of real applications still render HTML directly from the server, and Express supports this natively through view engines.
What’s Covered
- View engines, what they are, and how Express uses one to render HTML.
- EJS, the most common Node.js view engine, plain JavaScript inside HTML.
- Passing data to views, rendering a template with real, dynamic values.
- Partials and layouts, reusing common HTML across multiple pages.
- Handlebars, an alternative “logic-less” templating syntax, including its own partials and layouts.
- A quick CRUD example, a small create-read-update-delete app built with Handlebars.
- Server-rendered views vs APIs, when each approach actually fits.
Hands-On
By the end of this module, you’ll have built Express routes that render real, dynamic HTML pages using EJS, complete with shared layouts and partials.
Next module: middleware, the mechanism that lets code run on every request before it reaches a route.