NodeJS Localhost LAN connection problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

NodeJS Localhost LAN connection problem

Hello, I have developed a NodeJS server code here below #################################### var http = require('http'); var fs = require('fs'); http.createServer(function (req, res) {   fs.readFile('mywebsite.html', function(err, data) {     res.writeHead(200, {'Content-Type': 'text/html'});     res.write(data);     res.end();   }); }).listen(8080); #################################### But whenever I run the code, this runs on my computer local host without any problem. But whenever I try connecting my mobile with computer LAN and opening the port 'localhost:8080' it says 'webpage refused to connect' I can not find out what the problem is here , even after being connected to the same LAN in my mobile, port 8080 throws refuse error. Do Wifi and Hotspot matter ? Because my Computer's Wifi is connected to my Mobile Hotspot Any solutions? Thanks for your valuable time

13th Apr 2020, 7:01 AM
[B.S.] BITTU
[B.S.] BITTU - avatar
6 Answers
+ 1
no, instead of http://localhost:8080 you should use http://192.168.2.xxx:8080 when connecting from mobile
13th Apr 2020, 1:50 PM
Gordon
Gordon - avatar
+ 3
Then, it's not localhost, you need to find the IP address of your computer. https://howchoo.com/g/mte2zgrhmjf/how-to-access-a-website-running-on-localhost-from-a-mobile-phone Something starting with 192.168.x.xxx
13th Apr 2020, 7:07 AM
Gordon
Gordon - avatar
+ 1
Subhojit Sikdar follow the way Gordon mentioned.
13th Apr 2020, 4:39 PM
Calviղ
Calviղ - avatar
+ 1
Thanks a lot to Calviղ Gordon for spending some time for me
15th Apr 2020, 11:43 AM
[B.S.] BITTU
[B.S.] BITTU - avatar
0
Use ipconfig to find ip address of your wireless internet connection
13th Apr 2020, 7:55 AM
Calviղ
Calviղ - avatar
0
Calviղ then I will have to replace the ip with port 8080 section right
13th Apr 2020, 8:32 AM
[B.S.] BITTU
[B.S.] BITTU - avatar