Node.js http-server 实现目录浏览服务方法
AI 概述
前期准备下载安装 http-server启动 http-server命令更多设置
前期准备
node.js v14.16.0
用 node.js 实现浏览服务
前提,你已经在本地安装好 Node.js
http-server 官网:点击这里
下载安装 http-server
$ npm install --global http-server
C:\Users\mybj\AppData\Roaming\npm\hs -> C:\User...
目录
前期准备
- node.js v14.16.0
- 用 node.js 实现目录浏览服务
- 前提,你已经在本地安装好 Node.js
- http-server 官网:点击这里
下载安装 http-server
$ npm install --global http-server C:\Users\mybj\AppData\Roaming\npm\hs -> C:\Users\mybj\AppData\Roaming\npm\node_modules\http-server\bin\http-server C:\Users\mybj\AppData\Roaming\npm\http-server -> C:\Users\mybj\AppData\Roaming\npm\node_modules\http-server\bin\http-server + http-server@0.12.3 added 30 packages from 40 contributors in 6.6s
启动 http-server
命令
http-server [path] [options]
[path]的默认值:先找 ./public ,否则使用 ./ 。
例如:
$ http-server Starting up http-server, serving ./ Available on: http://192.168.17.140:8081 http://192.168.44.1:8081 http://192.168.208.1:8081 http://192.168.137.1:8081 http://127.0.0.1:8081 Hit CTRL-C to stop the server
效果如下:

更多设置
$ http-server --help
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.js 代码实现目录浏览服务。
以上就是http-server 实现目录浏览服务的方法,希望对大家有用,感谢阅读。
以上关于Node.js http-server 实现目录浏览服务方法的文章就介绍到这了,更多相关内容请搜索码云笔记以前的文章或继续浏览下面的相关文章,希望大家以后多多支持码云笔记。
声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 admin@mybj123.com 进行投诉反馈,一经查实,立即处理!
重要:如软件存在付费、会员、充值等,均属软件开发者或所属公司行为,与本站无关,网友需自行判断
码云笔记 » Node.js http-server 实现目录浏览服务方法
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 admin@mybj123.com 进行投诉反馈,一经查实,立即处理!
重要:如软件存在付费、会员、充值等,均属软件开发者或所属公司行为,与本站无关,网友需自行判断
码云笔记 » Node.js http-server 实现目录浏览服务方法
微信
支付宝