一、已經安裝nodejs的電腦,有一個方便通過http訪問本地文件夾。文件夾服務器
static files over HTTP
,並不是我們平常說的node那個web服務器哦
二、好處
可以方便實現跨域
和防止跨域(google表現的同源策略)
等
三、參考網址
官方網址:https://www.npmjs.com/package/http-server
棧溢出:
https://stackoverflow.com/questions/16333790/node-js-quick-file-server-static-files-over-http/24575241#24575241?newreg=f45f9198b20d4fc69d86e009ee6149d9
四、使用方法
五、我的使用
1,前提我的電腦已經有node了
2,cmd中輸入
:npm install http-server -g
3,cmd中找到文件夾
:cd C:\Users\Administrator\Desktop\11
,我隨便在桌面建的一個文件夾,你也隨便建一個,轉到就好了
4,cmd中輸入
:http-server
5,最后一步,會給你爆出兩個個地址
C:\Users\Administrator\Desktop\11>http-server
Starting up http-server, serving ./
Available on:
http://192.168.1.101:8080
http://127.0.0.1:8080
6, 在瀏覽器輸入:http://192.168.1.101:8080 或者 http://127.0.0.1:8080 兩個其中一個。
7,當你訪問上圖的文件的時候,會檢測到你訪問的瀏覽器UA,並顯示在cmd上。