liveBook · Manning

Http-server module

As explained in Pro Angular 16

http-server is an npm package and command-line tool that serves static files over HTTP.

The http-server package is a simple, self-contained command-line HTTP server for delivering static application files during local testing. section 9.5.1

Serve a production build

After building the application, run `npx http-server@14.1.1 dist/example --port 5000`. The command downloads and executes the package, serves the dist/example directory, and listens on port 5000. Open http://localhost:5000 in a browser; stop the server with Control+C. section 9.5.1

Prerendering uses the same workflow: generate static HTML first, then serve the resulting browser directory separately. With JavaScript disabled, the browser receives prerendered documents; with JavaScript enabled, the application rehydrates them. section 27.5.2

Use the module when you need to:

  • Inspect a production build through a local HTTP URL rather than opening files directly. section 9.5.1
  • Deliver prerendered application output after the prerender command has created static HTML. section 27.5.2
  • Test loading behavior under simulated fast or slow 3G network conditions. section 8.2.5
Listing 9.18. Running the production build
npx http-server@14.1.1 dist/example --port 5000

Shows the complete command for serving a production build with http-server 14.1.1 on port 5000. section 9.5.1

How Pro Angular 16 covers it

How deep it goes
Demonstrates installation-free execution, directory and port configuration, browser testing, and manual shutdown.
Examples
Uses dist/example on port 5000 and dist/exampleApp/browser on port 4500 as served application directories.
What it assumes
Assumes that a production or prerendered output directory already exists because the server does not generate that content.
What you can do after
Operate/configure it: serve generated application directories at selected local ports and inspect their browser behavior.
How it connects
Connects static file serving with production builds, prerendering, rehydration, and HTTP testing.

Also explained in

Compare how 2 books explain http-server module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.