2 thoughts on “How to use promises for results instead of callbacks?

  1. I found the answer:

    function findOne(db, opt) {
      return new Promise(function(resolve, reject) {
        db.findOne(opt, function(err, doc) {
          if (err) {
            reject(err)
          } else {
            resolve(doc)
          }
        })
      })
    }
    findOne(this.db, {
      abc: 123
    }).then(function(doc) {
    });