Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openshift port for node.js

I have a server that won't start correctly on 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:

info: socket.io started warn: error raised: Error: listen EACCES DEBUG: Program node server.js exited with code 0 DEBUG: Starting child process with 'node server.js' Listening on 8080...

How can I solve this?

like image 492
user1907859 Avatar asked Jun 17 '14 09:06

user1907859


1 Answers

You need to bind the listening IP address to process.env.OPENSHIFT_NODEJS_IP. Here is the example from my working code (I'm using Express) on 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
});
like image 106
adijiwa Avatar answered Oct 17 '22 04:10

adijiwa