nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
1 of 1
1How to serve static files?
Express.jsExpress.js
Basics
Routing
Middleware
Static Files
01 / 01

How to serve static files?

Difficulty: 4/10
express static middleware, caching headers, security

To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express. The function signature is: express.static(root, [options]). The root argument specifies the root directory from which to serve static assets.

To create a virtual path prefix (where the path does not actually exist in the file system) for files that are served by the express.static function, specify a mount path for the static directory, as shown below:
the path that you provide to the express.static function is relative to the directory from where you launch your node process. If you run the express app from another directory, it’s safer to use the absolute path of the directory that you want to serve:

Scenario Questions

0-2 years experience

  1. 1You need to expose a folder of images at the URL path '/static' in an existing Express app. How would you set that up?
  2. 2If a client requests '/static/logo.png' and receives a 404, what are the typical reasons in Express?
  3. 3Which middleware do you use to serve static files, and where should it be placed in the middleware chain?

2-5 years experience

  1. 1Your team added express.static to serve a React build, but after deployment the CSS files aren't loading. Walk me through how you'd debug the issue.
  2. 2We want long‑lived caching for JavaScript bundles while keeping HTML fresh. How would you configure Express static to achieve that?
  3. 3Explain how you would protect against directory‑traversal attacks when serving static assets.

5-8 years experience

  1. 1Our service handles millions of requests per day and serves static assets from Express. What performance optimizations would you consider, and when would you move to a CDN?
  2. 2We need to serve versioned static files (e.g., app.v1.2.3.js) and automatically purge old versions. How would you design a solution within Express and the deployment pipeline?
  3. 3Discuss the trade‑offs of using express.static with custom cache‑control headers versus a reverse proxy like Nginx for static content.

8+ years experience

  1. 1Our monorepo contains multiple microservices, each with its own static assets. How would you architect a shared static‑asset strategy across teams, balancing deployment speed, cache invalidation, and security?
  2. 2We are migrating from an on‑premises Express server serving static files to cloud object storage (e.g., S3) with an edge CDN. What steps and considerations would you outline for a seamless transition?
  3. 3How would you establish a governance model for static‑asset versioning, CDN invalidation, and compliance across all products in a large organization?

Follow-up Questions

  • What happens if you register the static middleware after your dynamic routes?
  • How would you adjust caching for HTML versus bundled assets?
  • When would you choose a CDN over Express for static content?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.