I tried a lot but am not able to get node to connect to Mongo in a simple mean app in the openshift node cartridge talking to the mongo cartridge. All goes fine but the application errors out (service temporarily unavailable error) if you go to the URL.
I have used proper environment variables and if I ssh to the instance and connect to mongo locally or run node server at the app root, all works fine.
But if I git push it, the build, deploy etc works fine but when I go to the application URL it gives an error. Please help. Not sure what the problem is since the code works fine locally and on the openshift server in the repo directory using 'node server' at command line.
==============================
**server.js**
=========
#!/bin/env node
// OpenShift sample Node application
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
// Load the module dependencies
var mongoose = require('./config/mongoose'),
express = require('./config/express'),
passport = require('./config/passport');
// Create a new Mongoose connection instance
var db = mongoose();
// Create a new Express application instance
var app = express();
// Configure the Passport middleware
var passport = passport();
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || 'localhost';
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
app.listen(port, ipaddress, function() {
console.log('%s: Node server started on %s:%d ...',
Date(Date.now() ), ipaddress, port);
});
// Use the module.exports property to expose our Express application instance for external usage
module.exports = app;
===========================
development.js
==============
// Invoke 'strict' JavaScript mode
'use strict';
var dbDefault = process.env.OPENSHIFT_MONGODB_DB_URL + process.env.OPENSHIFT_APP_NAME || 'mongodb://localhost:27017/someapp';
// Set the 'development' environment configuration object
module.exports = {
db : dbDefault ,
sessionSecret: 'developmentSessionSecret'
};
================================
mongoose.js
===========
// Invoke 'strict' JavaScript mode
'use strict';
// Load the module dependencies
var config = require('./config'),
mongoose = require('mongoose');
// Define the Mongoose configuration method
module.exports = function() {
// Use Mongoose to connect to MongoDB
var db = mongoose.connect(config.db);
// Load the application models
require('../app/core/models/user.server.model');
// Return the Mongoose connection instance
return db;
};
===========================
logs - node
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'