Node.js use of http-server open a local server

With html to write a page, you want to see the effect of adaptation on the phone, but did not suffer a direct view HTML on the phone. Think of mobile phones and computers within a local area network, can set up a web server within a LAN it?

1. Download http-server

Obviously, you need to download node.js (not write)

Install http-server:

npm install http-server -g

2, open http-server service

Terminal enters the destination folder, then enter the terminal:

C: \ the Users \ 20928 \ Documents \ VS_Code \ Html> HTTP Server -C-- 1   (⚠️ only input http- Server, then the updated code, the page will not sync update) 
Starting up HTTP -server, the Serving ./ 
the Available ON: 
  HTTP: // 172.17.151.1:8080 
  HTTP: // 192.168.159.1:8080 
  HTTP: // 192.168.176.1:8080 
  HTTP: // 127.0.0.1:8080 
  HTTP: // 192.168.2.200:8080

Then, visit the above web site and found open ......

Solution: Install anywhere

anywhere installation command:npm install -g anywhere

Then run the command: anywhere -p 8080(-p followed by a port number)

C:\Users\20928\Documents\VS_Code\Html>anywhere -p 8080
Running at http://172.17.151.1:8080/
Also running at https://172.17.151.1:8081/

// At this point, the actual URL that can be accessed only two

In fact , do not install anywhere can access: just add the file name to the URL

For example, http://172.17.151.1:8080/hello.html

3, the effect

 At this point, the mobile terminal can also access this page.

But it seems that the host can only access the LAN IP, usually 192.168.XX

 

 

Reference links:

1. https://www.cnblogs.com/wukaiBK/p/11386614.html

2. https://blog.csdn.net/xigua3188/article/details/99542884

 

Guess you like

Origin www.cnblogs.com/lfri/p/11828557.html