← 返回命令列表

Linux command

http-server 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Start server

http-server

Specify port

http-server -p [8080]

Specify directory

http-server [./public]

Enable CORS

http-server --cors

Enable gzip

http-server -g

SSL server

http-server -S -C [cert.pem] -K [key.pem]

说明

http-server is a simple, zero-configuration static file server for Node.js. It serves files from a directory over HTTP, making it ideal for quickly testing frontend builds, sharing files on a local network, or previewing static sites. Install via `npm install -g http-server`. Serves the current directory by default on port 8080.

参数

-p, --port _PORT_
Port number (default 8080).
-a _ADDRESS_
Listen address.
-c _SECONDS_
Cache time.
--cors
Enable CORS headers.
-g, --gzip
Enable gzip.
-S, --ssl
Enable SSL.
-C _FILE_
SSL certificate file (default: cert.pem).
-K _FILE_
SSL key file (default: key.pem).
-o
Open browser after starting.
-P, --proxy _URL_
Proxy unresolvable requests to this URL.
--no-dotfiles
Do not serve dotfiles.

FAQ

What is the http-server command used for?

http-server is a simple, zero-configuration static file server for Node.js. It serves files from a directory over HTTP, making it ideal for quickly testing frontend builds, sharing files on a local network, or previewing static sites. Install via `npm install -g http-server`. Serves the current directory by default on port 8080.

How do I run a basic http-server example?

Run `http-server` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -p, --port _PORT_ do in http-server?

Port number (default 8080).