node http-server使用

http-server

安裝

項目下安裝

npm install http-server
#帶版本
npm install http-server@4

全局安裝

npm i -g http-server

github地址

https://github.com/http-party/http-server

啓動

http-server
或者
hs

推薦

# 開發時不啓用緩存
http-server -c-1

命令查看

npm info http-server

輸出內容

C:\Users\Administrator>npm info http-server

[email protected] | MIT | deps: 10 | versions: 38
A simple zero-configuration command-line http server
https://github.com/http-party/http-server#readme

keywords: cli, command, http, server

bin: http-server, hs

dist
.tarball: https://registry.npmjs.org/http-server/-/http-server-0.12.1.tgz
.shasum: 629ae9a8c786587ee21b0ff087b670f69b809d8c
.integrity: sha512-T0jB+7J7GJ2Vo+a4/T7P7SbQ3x2GPDnqRqQXdfEuPuUOmES/9NBxPnDm7dh1HGEeUWqUmLUNtGV63ZC5Uy3tGA==
.unpackedSize: 21.0 kB

dependencies:
basic-auth: ^1.0.3    corser: ^2.0.1        http-proxy: ^1.17.0   optimist: ~0.6.1      secure-compare: 3.0.1
colors: ^1.3.3        ecstatic: ^3.3.2      opener: ^1.5.1        portfinder: ^1.0.20   union: ~0.5.0

maintainers:
- bigbluehat <[email protected]>
- indexzero <[email protected]>
- thornjad <[email protected]>

dist-tags:
latest: 0.12.1

published 3 months ago by thornjad <[email protected]>

查看命令參數

hs -h
或
http-server --help

例子

C:\Users\Administrator>hs -h
usage: http-server [path] [options]

options:
  -p --port    Port to use [8080]
  -a           Address to use [0.0.0.0]
  -d           Show directory listings [true]
  -i           Display autoIndex [true]
  -g --gzip    Serve gzip files when possible [false]
  -b --brotli  Serve brotli files when possible [false]
               If both brotli and gzip are enabled, brotli takes precedence
  -e --ext     Default file extension if none supplied [none]
  -s --silent  Suppress log messages from output
  --cors[=headers]   Enable CORS via the "Access-Control-Allow-Origin" header
                     Optionally provide CORS headers list separated by commas
  -o [path]    Open browser window after starting the server.
               Optionally provide a URL path to open the browser window to.
  -c           Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds.
               To disable caching, use -c-1.
  -t           Connections timeout in seconds [120], e.g. -t60 for 1 minute.
               To disable timeout, use -t0
  -U --utc     Use UTC time format in log messages.
  --log-ip     Enable logging of the client's IP address

  -P --proxy         Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com

  --username   Username for basic authentication [none]
               Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME
  --password   Password for basic authentication [none]
               Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD

  -S --ssl     Enable https.
  -C --cert    Path to ssl cert file (default: cert.pem).
  -K --key     Path to ssl key file (default: key.pem).

  -r --robots        Respond to /robots.txt [User-agent: *\nDisallow: /]
  --no-dotfiles      Do not show dotfiles
  -h --help          Print this list and exit.
  -v --version       Print the version and exit.

node的package.json配置

  "scripts": {
    "start": "node ./bin/www",
    "server": "http-server",
    "server-nocache": "http-server -c-1"
  }

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章