Skip to content

Instantly share code, notes, and snippets.

Created November 8, 2012 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4040697 to your computer and use it in GitHub Desktop.
Save anonymous/4040697 to your computer and use it in GitHub Desktop.
test to connect to mongo from nodejitsu
var http = require('http');
var port = (process.env.VMC_APP_PORT || 3000);
var host = (process.env.VCAP_APP_HOST || '165.225.133.190');
http.createServer(function (req, res) {
var mongo = require('mongodb'),
Server = mongo.Server,
Db = mongo.Db;
var server = new Server('masterMongoDB', 27020, {auto_reconnect: true},{safe:true});
var db = new Db('exampleDb', server);
db.open(function(err, db) {
if(!err) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("DB connection successfull- You are now conected");
res.end();
}
else{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("DB connection Failed-"+err);
res.end();
}
});
}).listen(port, host);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment