The port for node.js will open

I have a server that will not start correctly in openshift. This is my code:

var connect = require("connect");
var port = process.env.OPENSHIFT_NODEJS_PORT  || 8080;
var httpServer = connect.createServer(connect.static(__dirname + "/public")).listen(port);
console.log("Listening on " + port + "...");

I keep getting this error:

information: socket.io running warning: error raised: Error: listen to EACCES DEBUG: The node server.js program exited with code 0 DEBUG: starting the child process using

How can i solve this?

+4
source share
2 answers

You need to bind the listening IP address to process.env.OPENSHIFT_NODEJS_IP. Here is an example from my working code (I use Express) in OpenShift.

var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
app.listen(port, ipaddress, function() {
    // Do your stuff
});
+9
source

We need to specify the binding to your OPENSHIFT_NODEJS_IP in your application:

var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; (do not forget quotes)
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
+3
source

Source: https://habr.com/ru/post/1544871/


All Articles