NodeJS Localhost LAN connection problem | Sololearn: Learn to code for FREE!

+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

4/13/2020 7:01:21 AM

[B.S.] BITTU

6 Answers

New Answer

+1

no, instead of http://localhost:8080 you should use http://192.168.2.xxx:8080 when connecting from mobile

+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

+1

Subhojit Sikdar follow the way Gordon mentioned.

+1

Thanks a lot to Calviղ Gordon for spending some time for me

0

Use ipconfig to find ip address of your wireless internet connection

0

Calviղ then I will have to replace the ip with port 8080 section right