0

I have been trying to run a simple node.js server using express from WSL2 at port 3000


const express = require('express');

const app = express();

app.get('/', (req, res) => {
    res.send('<h1>Hello World</h1>');
});

app.listen(3000, () => {
    console.log('Run at http://localhost:3000');
});

I can connect from in my computer's browser and see the 'Hello World' but I'm not able to connect from a external device's browser (My phone,etc...) i put my windows ip both wsl2 ip , but none works

also i tried to set a host in '0.0.0.0' like this but it didn't work either

app.listen(3000, '0.0.0.0', () => {
    console.log('Run at http://localhost:3000');
});

Cannot connect server image

When i try to run the same server but using git bash in my windows everything works alright...

Any suggestions ?

I'd appreciate your help!

  • *Short answer:* If you can, use WSL1 for this. *More Details:* While it's a different server being discussed, your problem is really the same as [this question](https://stackoverflow.com/questions/65275743/communictaion-in-local-area-networklan-problem-about-ros-on-wsl2), with the same answer I gave there. Also please see the *exact* same (Node with WSL2), question and [answer](https://superuser.com/a/1618446/1210833) on Super User. Let me know if, for some reason, you still have questions after reading those, and we can take a look at how your particular case may differ. Thanks! – NotTheDr01ds Jul 07 '21 at 11:22

1 Answers1

0

I had the same problem and found the answer in a reddit discussion Change o route from "/" to "/test" and return a "ok" and you'll se that your server is responding