Created
November 8, 2012 18:45
-
-
Save anonymous/4040697 to your computer and use it in GitHub Desktop.
test to connect to mongo from nodejitsu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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