I am working on nodejs app,i wrote server listening code,then i deployed code into openshift hosting,there i am getting 503 response,in local if i run this code it is properly working.
code:
var http = require('http');
var express = require('express');
var fs = require('fs');
var app = express();
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');
http.createServer(app).listen(app.get('port'), app.get('ip'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.get('/', function (req, res) {
res.send('Hello World!');
});
Do you pass the
OPENSHIFT_NODEJS_IP
variable? Quite often the problem is that the nodejs application is listening on IP127.0.0.1
like in this case, but should on0.0.0.0
. If that doesn't help please provide more details on how you created the application in OpenShift.Here are a few tricks that might help determine what the issue is. The first way I approach it is to ssh into the OpenShift cartridge. Assuming the name of your application is hello_world:
Once inside, type:
This should list out the running node processes along with the ips and ports that each is listening to. I have two node applications running, so my output looks like this:
So my node applications are listening on an actual ip address other than localhost. My guess is that you will see something to this effect:
Next, check your environment:
Mine looks like this:
So I can see that the OPENSHIFT_NODEJS_PORT and OPENSHIFT_NODEJS_IP matches the output of my lsof statement above, so I'm all good.
I'm sure you will see a discrepancy after doing all this, and that will be your clue.