ES6 Promise with the "co" module I was trying to use the ES6 Promise with the "co" module to write the async code without callback. Though actual async call is neat and clean, I still have to add wrapper method to return Promise object which made it little bulky. Any feedback to improve this code quality will be appreciated.

crud.js
'use strict';
const db = require("./dbmanager").db;
const co = require("co");

module.exports = {

  getAllDocuments: (collectionName)=&gt; {

    //This line of code returning "Promise" object make code bulky. Now I have two wrapper, one for "Promise" and second for "co".
    return new Promise((resolve, reject) =&gt; {

      co(function*() {
        let docs = yield db.collection(collectionName).find().toArray();
        resolve(docs);

      }).catch((err) =&gt; {
        reject(err);
      });

    });
  }

}; 

book.js

'use strict';
const dbcrud   = require("./../mongodb/crud");
const co = require("co");
module.exports = {

  getTransactions: (callback) =&gt; {
    co(function*() {

      var books = yield dbcrud.getAllDocuments('books');
      callback(null, books);

    }).catch((err) =&gt; {
      console.log("Error " + JSON.stringify(err));
      callback(err, null);
    });
  }

};
After going through the &quot;co&quot; GitHub code, I was able to remove the extra boilerplate code. I made following changes to improve my code:

Used the &quot;co&quot; promise and return it in my async function. This help to remove the extra &quot;Promise&quot; wrapper code.
To resolve the &quot;co&quot; promise, I returned the &quot;Promise&quot; as per fails/success scenario.
When making call to MongoDB native driver, used &quot;.catch&quot; to catch the error there itself and apply logic.

Following is my final version which is neater and cleaner using the &quot;co&quot; module:
crud.js
'use strict';
const db = require(&quot;./dbmanager&quot;).db;
const co = require(&quot;co&quot;);

module.exports = {

  getAllDocuments: (collectionName)=&gt; {
      //return the &quot;co&quot; promise instead of using &quot;Promise&quot; boilerplate code
      co(function*() {
        let docs = yield db.collection(collectionName).find().toArray().catch(function(err) {
        //in case of error, return the custom message and log the error returned by mongodb driver
        console.log('Error occurred to get documents', err);
        return Promise.reject(new Error(`Error occurred to get documents`)); //return the Promise which will be used by &quot;co&quot;
      });
        return Promise.resolve(docs); //return the Promise which will be used by &quot;co&quot;

      });  
  }
}; 

book.js
'use strict';
const dbcrud   = require(&quot;./crud&quot;);
const co = require(&quot;co&quot;);
module.exports = {

  getTransactions: (req, res) =&gt; {
   //use &quot;co&quot; to make asyn function call without callback
    co(function*() {
      let transactions = yield dbcrud.getTransactions('transactions');
      res.json(transactions);
    }).catch((err) =&gt; {
      console.error(`[ERROR:Controller:API:getTransactions]: error`, err);
      res.status(500);
      res.json({error: err.message});
    });
  },

};