在写前端页面中,经常会在浏览器运行HTML页面,从本地文件夹中直接打开的一般都是file协议,当代码中存在http或https的链接时,HTML页面就无法正常打开,为了解决这种情况,需要在在本地开启一个本地的服务器。
本文是利用node.js中的http-server,开启本地服务,步骤如下:
node.js官网地址: https://nodejs.org
下载完成后在命令行输入命令$ node -v以及$ npm -v检查版本,确认是否安装成功。
http-server在终端输入:
$ npm install http-server -g
http-server服务终端进入目标文件夹,然后在终端输入:
$ http-server
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://192.168.8.196:8080
Hit CTRL-C to stop the server
http-server服务按快捷键CTRL-C
终端显示^Chttp-server stopped.即关闭服务成功。
原文:https://www.cnblogs.com/nolaaaaa/p/9126385.html