Home > Web Front-end > JS Tutorial > NodeJs mobile phone access to local server case analysis

NodeJs mobile phone access to local server case analysis

php中世界最好的语言
Release: 2018-05-22 10:02:29
Original
1831 people have browsed it

This time I will bring you a case analysis of NodeJs mobile phone accessing the local server. What are the precautions for NodeJs mobile phone to access the local server. The following is a practical case, let's take a look.

As a front-end engineer who doesn't understand the background, it is a very good choice to use node.js to build a server. Let’s build a simple server:

var app=require("express")();
//接收来自用户的任何请求
app.use(function(req,res){
 res.write("The response from server");
 res.end();
});
Copy after login

This IP address, the poster always thought that specifying the IP address here means that others can access your server by entering this IP address, but this is not the case. If you specify an IP address, it means that only the IP address can be accessed. So, generally, if anyone has access, don't write.

//port写端口号,ip写ip地址,
app.listen(port,ip,function(err){
 if(err){
  console.error(err);
 }else {
  console.info("服务器起动成功..");
 }
});
Copy after login

1. Make sure that your computer and mobile phone are in the same network segment, that is, they are both in the same LAN. This can be achieved by connecting both the mobile phone and the computer to a wireless network;

2 . Enter ipconfig in the computer cmd to view the IP address of the current wireless network, and then copy the IP address to the monitored IP address. When accessing on the mobile phone, directly enter the IP address and port number; for example: 192.1.1.103

3 . Make sure that the port number that the server you built is listening is turned on on the computer (in order to prevent conflicts, it is not recommended to use port 80, more than 6000 ports, just write it casually, for example: 6868). Please refer to Baidu for details on how to turn it on, here No explanation;

If you still can't access it after turning it on, then there is only one ultimate method, turn off the firewall. After everything is set up successfully, enter 192.1.1.103:6868 in the mobile browser to access it successfully.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps to implement seamless carousel and left and right clicks with jQuery

node builds the server and writes the interface , Detailed explanation of interface adjustment and cross-domain methods

The above is the detailed content of NodeJs mobile phone access to local server case analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template