0

node project run completely fine on localhost but not able to run on domain, Please help me to resolve this this.

app.listen(3000,'APP_PRIVATE_IP_ADDRESS' function(err,rslt){
    if(err){
        console.log(err);
    }
    else{
    console.log("App Started on PORT 3000");
}
})

when i run the node server.js on terminal it print the message "App Started on PORT 3000" but when i run on the web it shows the error site can't be reached.

tanu
  • 31
  • 8
  • 2
    Possible duplicate of [Node.js connect only works on localhost](https://stackoverflow.com/questions/14043926/node-js-connect-only-works-on-localhost) – Toan Tran Jun 01 '17 at 06:01
  • 1
    Uh - do you think maybe the site can't be reached? Q: Can you ping that address? Q: Is there a router or firewall between your PC and tne Node app that might be blocking that endpoint ("endpoint" == IP address + Port)? Binding to "0.0.0.0" is part of the solution - but not necessarily the whole solution :( – paulsm4 Jun 01 '17 at 06:02
  • are you accessing it with public ip or domain name ? if with domain name did you map the A records with the server ip? – chetan dev Jun 01 '17 at 06:12

1 Answers1

0

Try using '0.0.0.0' symbolic IP, it means bind all IP's or any IP.

app.listen(3000, '0.0.0.0', function(err, rslt){
    if(err){
        console.log(err);
    }
    else{
        console.log("App Started on PORT 3000");
    }
});

Hostname is optional, so this is equivalent:

app.listen(3000, function(err, rslt){
    if(err){
        console.log(err);
    }
    else{
        console.log("App Started on PORT 3000");
    }
});

In the case of that you want to specify the IP version, this two usage make difference. If you provide '0.0.0.0' value for hostname parameter, only IPv4 binding happens and only IPv4 request are accepted and listened. If this parameter is not specified, both IPv6 and IPv4 bindings happen.

burak
  • 3,839
  • 1
  • 15
  • 20
  • Then, there may be any other problem with your environment. On which platform are you hosting your application? – burak Jun 01 '17 at 06:03