Views and Static Content in Express.js
Views and Static Content is the fourth chapter of the free Express.js tutorial. It shows how Express sends whole web pages, both built on the server and served as files.
What the lesson covers:
- Views and Static Files: Building HTML pages with EJS templates, passing data, loops, conditions, partials and safe escaping, then serving CSS, images and scripts with
express.static, caching, single-page app fallbacks and keeping private files safe.
The lesson starts with the difference between static and dynamic HTML. You set up EJS as a view engine, use its tags, pass data into templates, reuse parts of a page with partials, and keep pages safe by escaping user input. Then you serve files with express.static: a public folder, mount paths, several folders, cache settings, serving a built front-end app, and keeping private files out of reach. You also see how to choose a template engine for your own projects.
The labs show the rendered page next to your code. Press Source to see the HTML Express sent.
Lessons in this section
- Views and Static Files
EJS templates, passing data, loops, conditions, partials and safe escaping, then serving CSS, images and scripts with express.static, caching, SPA fallbacks and keeping private files safe.
- Render EJS templates with data
- Use loops, conditions and partials
- Escape output to stop XSS
- Serve static files with express.static