Objective
In the writing front page, often in the browser run HTML page, directly open from the local folder is generally a file
protocol, when the code exists http
or https
the link, the HTML page will not open normally, in order to resolve this situation, you need to open a local server locally.
This article is node.js
in the use of http-server
, open Local services, the steps are as follows:
1 Downloads
node.js
Website address: https://nodejs.org
After the download is complete, enter the command at the command line $ node -v
and $ npm -v
check the version to verify that the installation was successful.
2 Downloads
http-server
In Terminal input:
$ npm install http-server -g
3 Open
http-server
Service
The terminal enters the destination folder and then enters the terminal:
$ http-serverStarting up http-server, serving ./Available on: http://127.0.0.1:8080 http://192.168.8.196:8080Hit CTRL-C to stop the server
4 Close
http-server
Service
Press the shortcut keyCTRL-C
The terminal shows ^Chttp-server stopped.
that the service was turned off successfully.
Use Http-server to open a local server