0

This is my backend code.

var port = normalizePort(process.env.PORT || '3009');
app.set('port', port);

var server = http.createServer(app);
const ip ='198.168.0.132'

server.listen(port, ip ,()=>{
  console.log(`Server running on ${ip}:${port}`);
});

I also tried with port 0.0.0.0 but didn't work. I also create a firewall inbound rule to accessed by everyone connected to LAN.

I am checking it on postman the result it not shows the desired result. Result on postman with my ip address

But when I do it with localhost:3009, I get the desired data. So how I run my api/backend with my ip address.

  • 1
    Don't limit listening to just one IP address. Remove the IP address restriction: `server.listen(port ,()=>console.log('Server running on ' + port ));` – slebetman May 13 '23 at 08:14
  • This is just for checking that it's run on this ip or not. – Ritik Rajvanshi May 13 '23 at 09:37
  • No. This is to allow access **only** from this IP. – slebetman May 13 '23 at 09:40
  • So.. what happens whan you create a TCP listening socket with an IP (in C/C++, not just javascript - node's http module (which express uses) merely pass the argument to C) is that the socket library will find the network interface (ethernet or wifi card) that has been assigned that IP address. Once it finds it it will listen only to that interface (ethernet or wifi card). The IP address is not a filter. It is a request to bind the listening socket to a specific network card. – slebetman May 13 '23 at 09:43
  • I get it, I also used 0.0.0.0 to listen from other ip connected with lan. – Ritik Rajvanshi May 13 '23 at 12:22
  • I got the answer ,the main problem is that I forgot to turn off the firewall. As i do it everyone connected with LAN is able to use my services. – Ritik Rajvanshi May 16 '23 at 18:09

0 Answers0