Home > Article > Web Front-end > Use your mobile phone to access a local server built with NodeJs
This time I will bring you the use of mobile phones to access the local server built by NodeJs. What are the precautions for using the mobile phone to access the local server built by NodeJs. The following is a practical case, let's take a look.
var app=require("express")(); //接收来自用户的任何请求 app.use(function(req,res){ res.write("The response from server"); res.end(); });
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("服务器起动成功.."); } });
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:
How to operate $emit and $on parent-child and sibling component communication in vue
How to operate ES5 With the default parameters of the processing function in the ES6 environment
The above is the detailed content of Use your mobile phone to access a local server built with NodeJs. For more information, please follow other related articles on the PHP Chinese website!