O'Reilly logo

Node.js the Right Way by Jim R. Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Single-Page Web Application

A single-page web application consists of an HTML page, CSS to style it, and JavaScript to perform the application logic. All of these things can be delivered as static files, meaning they don’t require any special server-side processing. You can just serve them up from the file system.

In this section, you’ll see how to serve static content from Express alongside your RESTful APIs. Some of the static content will come from third-party dependencies, which we’ll pull from Bower.

Serving Static Content with Express

Express comes with a convenient way to serve static files. All you have to do is use the express.static middleware and provide a directory. For example, these lines appear in the b4 server:

web-app/b4/server.js ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required