Serving Static Files

The static middleware is very commonly used Express middleware. The static middleware allows you to server static files directly from disk to the client. You can use static middleware to support things like JavaScript files, CSS files, image files, and HTML documents that do not change. The static module is extremely easy to implement and uses the following syntax:

express.static(path, [options])

The path parameter specifies the root path from which the static files will be referenced in the requests. The options parameter allows you to set the following properties:

Image maxAge: The browser cache ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.