I am trying to deploy my node.js application (with express and mongoose) to openshift and I am not able to do so. The application works perfectly on my local environment.
my entry point is the file /bin/www
I establish this as the entry point on openshift with this line in the package.json file (per this thread):
"main": "bin/www",
I have made sure to set my mongodb connection using environment variables according to the guide like so:
// default to a localhost configuration:
var mongoConnectionString = 'mongodb://127.0.0.1/code-blog';
// if OPENSHIFT env variables are present, use the available connection info:
if (process.env.OPENSHIFT_MONGODB_DB_PASSWORD) {
mongoConnectionString = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" +
process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "@" +
process.env.OPENSHIFT_MONGODB_DB_HOST + ':' +
process.env.OPENSHIFT_MONGODB_DB_PORT + '/' +
process.env.OPENSHIFT_APP_NAME;
}
mongoose.connect(mongoConnectionString);
The error that I get is:
remote: Waiting for application port (8080) become available ...
remote: Application 'codeblog' failed to start (port 8080 not available)
remote: -------------------------
remote: Git Post-Receive Result: failure
remote: Activation status: failure
remote: Activation failed for the following gears:
remote: 558a25bd5973ca7a74000162 (Error activating gear: CLIENT_ERROR: Failed to
execute: 'control start' for /var/lib/openshift/558a25bd5973ca7a74000162/nodejs
remote: #<IO:0x00000000b49380>
remote: #<IO:0x00000000b49308>
remote: )
remote: Deployment completed with status: failure
remote: postreceive failed
To ssh://558a25bd5973ca7a74000162@codeblog-donaldsubert.rhcloud.com/~/git/codebl
og.git/
29635a8..7a0e926 master -> master
This is peculior to me because I do not specify port 8080 anywhere. In fact, the default port is specified here:
var port = normalizePort(process.env.OPENSHIFT_NODEJS_PORT || "3000");
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
app.set('port', port);
var server = http.createServer(app);
I am not really sure where to go from here. I don't seem to have enough information to determine my next step.
[edit] I added some logging to test what port this is running on, but the logging statement is never run. Here is the code
console.log("TEST TEST TEST");
var app = require('../app');
var debug = require('debug')('ProjectTemplate:server');
var http = require('http');
var port = normalizePort(process.env.OPENSHIFT_NODEJS_PORT || "3000");
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
console.log("PORT: ", port);
and output
TEST TEST TEST
module.js:340
throw err;
^
Error: Cannot find module './routes/logIn'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/lib/openshift/558a25bd5973ca7a74000162/app-root/ runtime/repo/app.js:26:13)
TEST TEST TEST
is from a logging statement at the beginning of the entry point file. Something seems to fail before it hits the console.log("PORT: ", port);
It is probable that this is something to do with app.js
where the MongoDb connection is made.
[/edit]