LiveLocalhost CLI usage

316 words, 2-minute read

The switches -? or --help show CLI help:

terminal

npx livelocalhost --help

The following CLI switches are supported:

CLIdescription
-v, --versionshow application version
-?, --helpshow CLI help
-E, --helpenvshow .env/environment variable help
-A, --helpapishow Node.js API help
-e, --env <file>load defaults from an .env file
-p, --serveport <port>HTTP port (default 8000)
-d, --servedir <dir>directory to serve (./)
-r, --reloadservice <path>path to reload service (/livelocalhost.service)
-j, --hotloadJSenable JavaScript hot reloading (false)
-w, --watchDebounce <ms>debounce time for file changes (default 600)
-l, --accessLogshow a server access log (false)

Examples #

Serve files from ./build/ at http://localhost:8080 and show the access log:

terminal

npx livelocalhost --serveport 8080 --servedir ./build/ --accessLog

The first two non-dashed parameters are presumed to be the port and directory. A simpler version of the same command:

terminal

npx livelocalhost 8080 ./build/ -l

Stop the server with Ctrl | Cmd + C.

Hot reloading #

Browser hot reloading is available when:

  1. the application has permission to watch OS files, and
  2. --reloadservice is a valid URL path starting /.

The default Server Sent Events service path for hot reloading is /livelocalhost.service. A client-side script at /livelocalhost.service.js is injected into all HTML files which automatically refreshes the browser:

You need only change --reloadservice when the default path is in use or you want to disable hot reloading (set any value that does not start with /).

Watch debouncing #

When a file is changed, LiveLocalhost waits 600ms. A hot reload is only triggered if no other files change within that time.

You can change the delay time using --watchDebounce. Note that very low settings can make reloading slower.