These are typically for local dev servers including static HTML or built output for Single-Page Apps like React.

These could be used in production too, but you should probably add something like Ngninx on top as a load balancer.

See also this gist which links here and shows options outside of Node.

Notes

  • Single-Page App mode like React, some support a flag like -s,--single, that is for . All not-found requests will go to index.html.
  • CORS mode - enable CORS to set Access-Control-Allow-Origin to *.
  • The base functionality will mostly be the same across packages. Some will have additional functionality like having a build command for production build, or features to enable with flags.

Packages and instructions

The instructions are for global install but also work at the project level.

Or use npx to run without installing (useful if you want to try out a few and get the latest version but slow to call each time).

You can also add the run commands to package.json. e.g. for start you can put serve -p 8080.

See the Express static server page for using Express.

In alphabetical order:

  • glance
  • harp
  • http-server
    • Install and run.
        $ npm i -g http-server
        $ http-server -a localhost
      
  • live-server
    • A great zero-config HTTP server with live reload capability.

    • Run with npx:
        $ npx live-server
      
    • Install and run.
        $ npm i -g live-server
        $ live-server
      
  • serve
    • Static file serving and directory listing

    • Created by the Vercel team.
    • This was recommended to me by React CLI when doing a build.
    • Run with npx:
        $ npx serve
      
    • Install and run.
        $ npm i -g serve
        $ serve
        $ serve build --single
        $ serve -p 8080 
      
  • serve-static
  • simple-server
    • Install and run.
        $ npm i -g simple-server
        $ simple-server public 3000
      
  • sirv and sirv-cli
    • You may use sirv as a very fast and lightweight alternative to serve-static.

    • Run with npx:
        $ npx sirv-cli
      
    • Install and run:
        $ npm i -g sirv
              
        $ # Serve.
        $ sirv
              
        $ # Dev mode
        $ sirv --dev
              
        $ # Open access to requests on the network.
        $ sirv --host
        $ sirv --port 8080 --cors --single
              
        $ # Target a directory.
        $ sirv build
        $ sirv public