I'm new to nodeJS, so i was just trying couple of things starting from 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 fine in my local, it displays the rows, but when i upload it to one of my appfog's app it does not display the rows, it just stops at "Start" and nothing else is displayed.
Please help, Thanks a lot in advance.