🌍 ExpressJS · subject

ExpressJS Advanced Topics in ExpressJS Syllabus

The Advanced Topics in ExpressJS syllabus for ExpressJS in full: 5 chapters and 15 topics, every one listed below, plus 50 Advanced Topics in ExpressJS flashcards with answers.

5Chapters
15Topics
50Flashcards

Advanced Topics in ExpressJS syllabus: all 5 chapters

Expand any chapter to see its topics and sub-topics.

  1. Template Engines

    3 topics
    • Using EJS
    • Using Pug
    • Using Handlebars
  2. Database Integration

    3 topics
    • Connecting to MongoDB with Mongoose
    • Using SQL Databases
    • ORMs and ODMs
  3. Authentication and Authorization

    3 topics
    • Using Passport.js
    • JWT Authentication
    • OAuth Integration
  4. Security Best Practices

    3 topics
    • Securing Express Applications
    • Preventing Common Vulnerabilities
    • Using Helmet.js
  5. Performance Optimization

    3 topics
    • Caching Strategies
    • Load Balancing
    • Profiling and Monitoring

ExpressJS Advanced Topics in ExpressJS flashcards — 50 questions with answers

  1. What is EJS in an Express.js application?

    EJS (Embedded JavaScript) is a templating engine that lets you generate HTML markup using plain JavaScript. It uses <% %> tags to embed logic and <%= %> to output escaped values into the page.

  2. How do you configure Express to use EJS as its view engine?

    Set app.set('view engine', 'ejs') and place templates in a 'views' folder. You then render with res.render('template', dataObject), passing variables the template can access.

  3. In EJS, what is the difference between the <%= %> and <%- %> output tags?

    <%= %> outputs a value with HTML escaping (safe against XSS), while <%- %> outputs the raw, unescaped value (used for injecting trusted HTML).

  4. What distinguishes Pug from EJS as a templating engine?

    Pug uses a clean, indentation-based (whitespace-significant) syntax with no closing tags, whereas EJS embeds JavaScript directly into standard HTML. Pug compiles its terse syntax down to HTML.

  5. How is a variable interpolated into text in a Pug template?

    Use #{variable} for escaped interpolation and !{variable} for unescaped interpolation. Attribute values can also use =, e.g. a(href=url).

  6. What is Handlebars and what is its core design philosophy?

    Handlebars is a 'logic-less' templating engine that uses {{ }} mustache-style expressions. It minimizes in-template logic, favoring helpers and partials to keep templates clean and presentation-focused.

  7. In Handlebars, what is the difference between {{expression}} and {{{expression}}}?

    {{expression}} HTML-escapes the output to prevent XSS, while {{{expression}}} (triple braces) renders the raw, unescaped HTML.

  8. What are Handlebars partials used for?

    Partials are reusable template fragments (e.g. headers, footers) that can be included in other templates with the {{> partialName}} syntax, promoting DRY markup.

  9. Compare EJS, Pug, and Handlebars on logic and syntax.

    EJS: full JavaScript logic embedded in HTML. Pug: indentation-based, terse, supports logic. Handlebars: logic-less mustache syntax relying on helpers/partials. EJS/Handlebars keep HTML-like markup; Pug replaces it with indentation.

  10. What is Mongoose and what does it provide over the native MongoDB driver?

    Mongoose is an ODM (Object Data Modeling) library for MongoDB and Node.js. It provides schema definitions, model-based CRUD, validation, middleware/hooks, type casting, and query building on top of the raw driver.

  11. How do you connect to MongoDB using Mongoose?

    Call mongoose.connect(uri) with a connection string like mongodb://localhost:27017/mydb (or a mongodb+srv Atlas URI). It returns a promise you await; the 'connected'/'error' events can also be listened to.

  12. In Mongoose, what is the relationship between a Schema and a Model?

    A Schema defines the structure, field types, and validation rules of documents. A Model is a constructor compiled from a Schema (via mongoose.model('Name', schema)) that provides an interface to create and query documents in a collection.

  13. What is the difference between an ORM and an ODM?

    An ORM (Object-Relational Mapper) maps objects to relational/SQL database tables and rows (e.g. Sequelize, TypeORM). An ODM (Object-Document Mapper) maps objects to document databases like MongoDB (e.g. Mongoose).

  14. Name two popular ORMs used with Express and SQL databases.

    Sequelize and TypeORM (Prisma and Knex are also common). They map JavaScript/TypeScript objects and models to relational tables and handle queries and migrations.

  15. What is the purpose of database migrations in an ORM workflow?

    Migrations are versioned scripts that incrementally apply and roll back schema changes (creating tables, altering columns), keeping the database schema in sync with the codebase across environments.

  16. What are the main benefits of using an ORM/ODM instead of writing raw SQL?

    Benefits include schema validation, object-oriented data access, protection against SQL injection via parameterization, database-agnostic code, relationship management, and built-in migration tooling. Trade-offs are performance overhead and less fine-grained query control.

  17. What is Passport.js and what is its core abstraction?

    Passport.js is authentication middleware for Node/Express. Its core abstraction is the 'strategy' — a pluggable module (e.g. local, JWT, OAuth) that defines how a request is authenticated.

  18. In Passport.js, what do serializeUser and deserializeUser do?

    serializeUser determines which user data is stored in the session (typically the user id). deserializeUser takes that stored id on subsequent requests and retrieves the full user object, attaching it to req.user.

  19. What is the Passport Local Strategy used for?

    The passport-local strategy authenticates users with a username/email and password submitted in a form, verifying credentials against a data store.

  20. What is a JSON Web Token (JWT) and what are its three parts?

    A JWT is a compact, URL-safe token for stateless authentication. It has three Base64URL-encoded parts separated by dots: Header (algorithm/type), Payload (claims), and Signature.

Show the other 30 Advanced Topics in ExpressJS flashcards
  1. How is a JWT's signature verified, and what does it guarantee?

    The signature is recomputed by hashing the header and payload with the secret/key and comparing it to the token's signature. It guarantees integrity and authenticity — that the token was not tampered with and was issued by the holder of the key.

  2. What is the difference between stateful (session) and stateless (JWT) authentication?

    Session auth stores state server-side and sends a session id cookie, requiring a server lookup each request. JWT auth is stateless: the token itself carries the claims and is verified by signature, needing no server-side session store, which aids scalability.

  3. What common JWT claims do 'exp', 'iat', and 'sub' represent?

    'exp' is the expiration time, 'iat' is the issued-at timestamp, and 'sub' is the subject (the principal/user the token is about). These are standard registered claims.

  4. What is OAuth 2.0 and what problem does it solve?

    OAuth 2.0 is an authorization framework that lets a third-party application obtain limited access to a user's resources without exposing the user's credentials. It delegates authorization via access tokens issued by an authorization server.

  5. Describe the OAuth 2.0 Authorization Code flow at a high level.

    The user is redirected to the provider to log in and consent; the provider redirects back with an authorization code; the server exchanges that code (plus its client secret) for an access token, then uses the token to call protected APIs.

  6. What is the difference between authentication and authorization?

    Authentication verifies who a user is (identity); authorization determines what an authenticated user is allowed to do (permissions/access). OAuth is primarily authorization; OpenID Connect adds authentication on top of OAuth.

  7. What is OpenID Connect (OIDC) and how does it relate to OAuth 2.0?

    OIDC is an identity/authentication layer built on top of OAuth 2.0. It adds an ID token (a JWT) that carries the user's identity claims, enabling 'sign in with' functionality that OAuth alone (authorization only) does not provide.

  8. What is Cross-Site Scripting (XSS) and how is it prevented in Express apps?

    XSS injects malicious scripts into pages viewed by other users. Prevent it by escaping/encoding output (default in EJS/Handlebars), validating and sanitizing input, and setting a Content-Security-Policy header.

  9. What is SQL injection and how do you prevent it?

    SQL injection sends malicious SQL through user input to manipulate queries. Prevent it with parameterized queries / prepared statements (or an ORM that parameterizes), plus input validation — never concatenate user input into SQL strings.

  10. What is Cross-Site Request Forgery (CSRF) and a common defense?

    CSRF tricks an authenticated user's browser into sending unwanted requests. Defenses include anti-CSRF tokens (synchronizer tokens), SameSite cookie attributes, and verifying the Origin/Referer header.

  11. What is Helmet.js and what does it do?

    Helmet.js is Express middleware that sets various security-related HTTP response headers (e.g. Content-Security-Policy, X-Content-Type-Options, Strict-Transport-Security) to protect the app from well-known web vulnerabilities.

  12. Which key security headers does Helmet.js set by default?

    By default Helmet sets headers such as Content-Security-Policy, X-Content-Type-Options: nosniff, X-Frame-Options (frameguard), Strict-Transport-Security (HSTS), X-DNS-Prefetch-Control, and it removes the X-Powered-By header.

  13. What does the Content-Security-Policy (CSP) header protect against?

    CSP restricts which sources (scripts, styles, images, etc.) the browser may load and execute, mitigating XSS and data-injection attacks by disallowing untrusted or inline resources.

  14. Why should you disable/remove the X-Powered-By header in Express?

    By default Express advertises 'X-Powered-By: Express', revealing the stack to attackers. Removing it (app.disable('x-powered-by') or via Helmet) reduces fingerprinting and targeted attacks.

  15. What is rate limiting and why is it used to secure Express apps?

    Rate limiting caps how many requests a client can make in a time window (e.g. via express-rate-limit). It mitigates brute-force attacks, credential stuffing, and denial-of-service by throttling abusive traffic.

  16. What is the purpose of input validation and sanitization middleware (e.g. express-validator)?

    It checks that incoming data matches expected types/formats (validation) and strips or escapes dangerous content (sanitization), defending against injection, XSS, and malformed-data errors before the data reaches business logic.

  17. What is caching and what are the main types relevant to a web server?

    Caching stores copies of data/computations to serve future requests faster. Main types: client/browser caching, CDN/edge caching, reverse-proxy caching, in-memory application caching (e.g. Redis), and database query caching.

  18. What is a cache hit ratio and how is it calculated?

    The cache hit ratio measures how often requests are served from cache. It is calculated as $$\text{hit ratio} = \frac{\text{hits}}{\text{hits} + \text{misses}}$$ A higher ratio means better cache effectiveness.

  19. Why is Redis commonly used as a caching layer with Express?

    Redis is an in-memory key-value store offering very low-latency reads/writes, TTL-based expiration, and data structures. It is used to cache query results, sessions, and computed data, reducing load on primary databases.

  20. What is the difference between cache TTL and cache invalidation?

    TTL (time-to-live) automatically expires a cached entry after a set duration. Invalidation actively removes or updates cached entries when the underlying data changes, ensuring stale data is not served.

  21. What do the HTTP Cache-Control and ETag headers do?

    Cache-Control directives (e.g. max-age, no-cache, public/private) tell clients/proxies how and how long to cache a response. ETag is a validator/fingerprint the client sends back (If-None-Match) so the server can reply 304 Not Modified if unchanged.

  22. What is load balancing and why is it needed for scaling Express apps?

    Load balancing distributes incoming requests across multiple server instances to improve throughput, availability, and fault tolerance. It prevents any single instance from becoming a bottleneck as traffic grows (horizontal scaling).

  23. Name common load-balancing algorithms.

    Round-robin, weighted round-robin, least-connections, IP hash (source-based/sticky), and least-response-time. Each decides how requests are routed among backend servers.

  24. What is the difference between horizontal and vertical scaling?

    Vertical scaling (scaling up) adds more resources (CPU/RAM) to a single machine. Horizontal scaling (scaling out) adds more machine/process instances behind a load balancer. Node/Express typically scales horizontally due to its single-threaded event loop.

  25. How does the Node.js cluster module or PM2 help scale an Express app on one machine?

    They fork multiple worker processes (typically one per CPU core) that share the same server port, allowing the app to utilize all cores and balance connections across workers, since a single Node process runs on one thread.

  26. What is a sticky session and when is it needed with load balancing?

    A sticky (session-affinity) load balancer routes a given client's requests consistently to the same backend instance. It is needed when session state is stored in-process; using a shared store (e.g. Redis) removes this requirement.

  27. What is application profiling and what does it measure?

    Profiling analyzes a running application to measure resource usage — CPU time, memory allocation, function call frequency, and latency — to identify performance bottlenecks and inefficient code paths.

  28. What is the difference between monitoring and profiling?

    Monitoring continuously observes an app's health and metrics (uptime, error rates, latency, throughput) in production over time. Profiling is a deeper, usually short-term analysis of resource consumption to find specific bottlenecks.

  29. What are the 'Four Golden Signals' of monitoring?

    Latency (time to serve requests), Traffic (demand/throughput), Errors (rate of failed requests), and Saturation (how full a resource is). Popularized by Google's SRE practice for monitoring services.

  30. Which tools are commonly used for monitoring Node.js/Express applications?

    Prometheus with Grafana (metrics/dashboards), the New Relic and Datadog APM agents, PM2 monitoring, and OpenTelemetry for distributed tracing. Node's built-in --prof flag and clinic.js help with profiling.

ExpressJS Advanced Topics in ExpressJS FAQ

What is in the ExpressJS Advanced Topics in ExpressJS syllabus?

ExpressJS Advanced Topics in ExpressJS is split into 5 chapters: Template Engines, Database Integration, Authentication and Authorization, Security Best Practices and Performance Optimization. Together they contain 15 topics.

How many chapters are in ExpressJS Advanced Topics in ExpressJS?

5 chapters, containing 15 topics. The largest chapter is Template Engines, with 3 topics.

Are there flashcards for ExpressJS Advanced Topics in ExpressJS?

Yes — a 50-card Advanced Topics in ExpressJS deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.