前言

  • node.js v12.18.2
  • 用 node.js 实现目录浏览服务
  • 前提,已经按照好Node.js
  • http-server 官网:https://www.npmjs.com/package/http-server

下载安装http-server

shell> npm install http-server -g
npm WARN dirservice@1.0.0 No description
npm WARN dirservice@1.0.0 No repository field.+ http-server@0.12.3
added 32 packages from 39 contributors and audited 32 packages in 42.284s2 packages are looking for fundingrun `npm fund` for detailsfound 0 vulnerabilities

启动http-server

命令

http-server [path] [options]

[path]的默认值:先找 ./public ,否则使用 ./

例如:

shell> http-server
Starting up http-server, serving ./
Available on:http://192.168.0.165:8080http://127.0.0.1:8080
Hit CTRL-C to stop the server

效果如下:

更多设置

帮助

shell> 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" headerOptionally 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 实现目录浏览服务相关推荐

  1. 【Node.js】编码实现目录浏览服务

    前言 node.js v12.18.2 用 node.js 实现目录浏览服务 (http-server实现,serve实现) 前提,已经按照好Node.js 编码实现 创建项目 找个自己喜欢的位置,创 ...

  2. 【Node.js】serve 实现目录浏览服务

    前言 node.js v12.18.2 用 node.js 实现目录浏览服务 (http-server) 前提,已经按照好Node.js serve 官网:https://www.npmjs.com/ ...

  3. Linux 创建网页服务,Linux使用Node.js建立访问静态网页的服务实例详解

    Linux使用Node.js建立访问静态网页的服务实例详解 一.安装node.js运行所需要的环境,: 二.创建node目录(/node/www),并在目录下创建node.js服务文件server.j ...

  4. 如何用 Node.js 实现一个简单的 Websocket 服务?

    最近正在研究 Websocket 相关的知识,想着如何能自己实现 Websocket 协议.到网上搜罗了一番资料后用 Node.js 实现该协议,倒也没有想象中那么复杂,除去注释语句和 console ...

  5. Node.js Git Server搭建及Git常用操作笔记

    Node.js Git Server搭建及Git常用操作笔记 安装Git工具即可在本地进行Git仓库的管理,如果要实现远程仓库则需要搭建Git Server.通过Node.js搭建Git Server ...

  6. node.js htttp文件服务器 遇到目录时搜索目录内默认html页面 廖雪峰javascript教程node.js中http部分练习题

    廖雪峰javascript教程node.js中http部分最后的练习题: https://www.liaoxuefeng.com/wiki/1022910821149312/1023025830950 ...

  7. node seneca_使用Node.js和Seneca编写国际象棋微服务,第1部分

    node seneca (This is Part 1 of a three-part series [Part 2, Part 3]) (这是一个由三部分组成的系列文章的第1部分[ 第2 部分 , ...

  8. node seneca_使用Node.js和Seneca编写国际象棋微服务,第3部分

    node seneca Finishing up a three-part series on writing a rules engine with Seneca microservices. 完成 ...

  9. Node.js 使用jQuery取得Nodejs http服务端返回的JSON对象示例

    server.js代码: // 内置http模块,提供了http服务器和客户端功能(path模块也是内置模块,而mime是附加模块) var http=require("http" ...

最新文章

  1. b-spline python_SciPyTutorial-一元B样条插值
  2. Python 读取和输出到txt
  3. python支持什么操作方式_python模拟点击常用的操作方法有哪些?
  4. HttpServletRequest和@Requestparam、@RequestBody、直接实体接收请求参数的区别与示例
  5. IBM DW上关于SOA的规范归纳
  6. 在15分钟内使用Spring Boot和Spring Security构建一个Web应用程序
  7. python 月报_python实践--月报分析之获取jira缺陷数据
  8. sed在行首(行尾)添加字符串;在某行后添加多行字符串-转
  9. [转载] python数学计算模块之math常用函数学习使用
  10. tfs管理java代码_TFS2010 版本控制权限设置
  11. IPtable 工作原理
  12. 利用FFmpeg合并音频和视频
  13. 知识共享平台开发-BUG[2014-11-27]
  14. Java获取今天是星期几
  15. Postgresql中xlog生成和清理逻辑
  16. android窗帘拉开动画,Android 窗帘(Curtain Menu)效果五之应用场景和使用方法
  17. 关于daemonize()
  18. 极大后验概率(MAP)- maximum a posteriori(转载)
  19. 根据IP获取城市-新浪ip接口
  20. 【Windows问题解决】 Win10无法打开Wlan,但是驱动正常的解决方案

热门文章

  1. MySQL 到PostgreSQL 的数据迁移工具
  2. 用lucene实现在一个(或者多个)字段中查找多个关键字
  3. 学习iBatis时的一个苦逼经历
  4. web.config总结
  5. 我所有的博客都在这里了,拿出来晒晒~~
  6. 微软回顾3项安全计划成果 有效降低******
  7. 各浏览器内核与C#WinForm开发Demo
  8. 用户sa登陆失败 SQLServer 错误18456的解决方法
  9. NHibernate+MySql (erro 解决方法)
  10. lombok 中的@Data注解