While the majority of modern Express applications serve JSON to JavaScript front-ends, a meaningful class of applications still need to render HTML server-side: marketing pages, email templates, admin dashboards, PDF generation pipelines, and server-side rendered views for SEO-sensitive content. Express supports server-side HTML rendering through a pluggable template engine system, and it serves static files like CSS, images, and client-side JavaScript through its built-in express.static() middleware. Understanding both capabilities is important even if your primary output is JSON, because every production application eventually needs a health-check page, an error page, or a simple admin view that does not justify building a full React front-end.
20 minintermediate
Template Engines and Static Assets
Analogy🏏Cricket
🏏 Think of it like cricket: In a Test match, there are multiple types of scheduled breaks and interruptions, each with different priority levels and timing rules. The lunch break (setTimeout) is scheduled for a specific time but can be delayed if a wicket falls just before — it fires at the next available opportunity after its scheduled time, not at the exact scheduled time. The drinks break (setImmediate) is taken at the end of the current over, as soon as the ongoing delivery sequence finishes. The umpire's over-rate check (process.nextTick) happens immediately after each delivery, before the next batsman faces — it cannot be deferred. The DRS review resolution (Promise microtask) happens between deliveries, after the umpire check but before any scheduled breaks. Just as the match referee would be furious if an umpire kept conducting over-rate checks after every single ball indefinitely (starving nextTick), the event loop is unable to proceed if process.nextTick callbacks keep registering new nextTick callbacks recursively. The insight is that each timer primitive is not just a delay mechanism — it is a specific position in a formal protocol, and misusing it violates that protocol's invariants.
Lesson 10 of 36
0% complete