I'm new to nodeJS, so I just tried a couple of things, starting with the basics.
I had a problem while retrieving data from MongoDB. So here is the code:
var port = (process.env.VMC_APP_PORT || 3000); var host = (process.env.VCAP_APP_HOST || 'localhost'); var http = require('http'); var mongo = require('mongodb'); http.createServer(function (req, res) { var mongoUrl = "mongodb://<userid>:<password>@linus.mongohq.com:10090/<db>"; if (process.env.VCAP_SERVICES) { mongoUrl = process.env.MONGOHQ_URL; } selectTable(req, res, mongoUrl); }).listen(port, host); var selectTable = function (req, res, mongoUrl) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write("Start\n"); mongo.connect(mongoUrl, function (err, conn) { conn.collection('Test', function (err, coll) { coll.find({}, {}, function (err, cursor) { cursor.toArray(function (err, items) { for (i = 0; i < items.length; i++) { res.write(JSON.stringify(items[i]) + "\n"); } res.end(); }); }); }); }); }
this works well in my local one, it displays strings, but when I load it into one of the appfog applications, it does not display strings, it just stops at "Start", and nothing else is displayed.
Please help, thanks a lot in advance.
source share