http-server的使用
安装http-server模块
npm install http-server -g
启动(在你要当服务器的文件夹下打开cmd)
http-server
打开文件
http://127.0.0.1:8080/index.html
问题
端口被占用
http-server <path> -a xxxx -p xxx
// path 目录地址,可以省略,默认是cmd打开的路径地址
//-a 监听地址
//-p 监听端口
这里的hs === http-server 是它的缩写
其他参数
参数作用
-p端口号 (默认 8080)-d显示目录列表 (默认 ‘True’)-i显示自动索引 (默认true)-e or --ext如果没有提供默认的文件扩展名(默认 ‘html’)-s or --silent禁止日志信息输出–cors允许跨域资源共享-o在开始服务后打开浏览器-c为 cache-control max-age header 设置Cache time(秒),例如: -c10 for 10 seconds (defaults to ‘3600’). 禁用 caching, 则使用 -c-1.-U 或 --utc使用 UTC格式,在控制台输出时间信息-P or --proxy通过一个 url地址,代理不能通过本地解析的资源-S or --ssl启用 https-C or --certssl证书文件的路径,默认是cert.pem-K or --keyssl密匙文件路径-h or --help显示帮助