How to use an node.js module to get and process data from my MongoDB database

Published on Author Code Father

The suggestion about mongoose is great and you can look into it, however I think you’ve already done the job with the fetching of the data from the db. You just need to access it in your main node flow.

You can try this:

module.exports.generateNav = function() {
  MongoClient.connect(process.env.MONGO_URL, function(err, db) {
    assert.equal(err, null);
    var output = fetchData(db, function(articles, categories) {
      combine(articles, categories, function(sitemap) {

    return (output);

And then in your main application you can call it in the following way:

var nav = require('nav');
navigation = nav.generateNav();