基于Node.js轻量级HTTP服务器有很多种,我们将以http-server为例(GitHub - http-party/http-server: a simple zero-configuration command-line http server),一般提供server服务的工具建议全局安装。
npm install http-server -g
启动日志如下:
命令为:http-server (在浏览器中访问以下三个地址中的任意一个,就能看到src目录下的 index.html 咯,案例是在src目录下启动的服务)
命令为:http-server src (若命令行工具在 “ \响应式 ” 文件夹中打开,要想达到上述效果,运行命令时需要带上 [path] 参数 )
[options] 参数可以指定端口、地址等等,例如指定服务在8888端口启动,命令为:http-server src -p 8080
npm install -g http-server
http-server -p 8080