NPM install -g HTTP-server is recommended

1. Enable command line input in the site directory

http-server

The path needs to be set in global access

http-server [path] [options]

The default path is./public

If the desired path does not exist, set another path

2. Set in package.json

“scripts”: {

“start”: “http-server -a 0.0.0.0 -p 8000”,

}

3. Browser access

Such as http://localhost:8080/index.html or http://localhost:8080/app.js

Note:

If you run a command in the current folder, the default root directory is the current folder

Parameters:

-p Port number (default 8080)

-a IP address (default 0.0.0.0)

-d Displays directory list (default ‘True’)

-i displays autoIndex (default ‘True’)

-e or –ext if no default file extension is provided (default ‘HTML ‘)

-s or –silent Disables the output of log information

— CORS Enable cORS via the access-Control-allow-origin header

-o Opens the browser after the service is started

-c Sets the cache duration (in seconds). For example, c10 10 seconds (the default value is 3600). To disable caching, please use.

The utc time format is used in -U and -UTC log messages.

-p or — proxy Proxies all requests. The given URL cannot be resolved locally. Such as. :- p someurl.com

-s or — SSL Enables HTTPS.

-c or -cert Path SSL certificate file (default :cert.pem).

-k or — Critical path SSL key file (default :key.pem).

-r or — Robot provides a robot. TXT (its contents default to user agent :* \ nDisallow:/)

-h or — help print the list and exit.

Common commands

NPM install -g http-server

Enable the http-server start or http-server command

Set path http-server [path] [options]

View the http-server -h parameter