简体   繁体   中英

How to setup node project to the linux server?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM