sher 发表于 2017-2-24 09:13:45

nodejs:本地文件夹http服务器http-server

一、已经安装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上。
  


六、我的文件夹

  
页: [1]
查看完整版本: nodejs:本地文件夹http服务器http-server