{"_id":"express-promise","_rev":"32-b9d44a6ee744305bee4b8d96e4f19e09","name":"express-promise","description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","dist-tags":{"latest":"0.4.0"},"versions":{"0.1.0":{"name":"express-promise","version":"0.1.0","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"express-promise ===============","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.0","dist":{"shasum":"6e5f5e84998a020c3201336fed9ca556be18f4a6","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.0.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.1":{"name":"express-promise","version":"0.1.1","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"express-promise ===============","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.1","dist":{"shasum":"746574dd9772dfb0a9f5c6bba2d2c8a82c76ec8d","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.1.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.3":{"name":"express-promise","version":"0.1.3","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.3","dist":{"shasum":"b20523eaba37e0fecd9c38385ce382a790d5165d","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.3.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.4":{"name":"express-promise","version":"0.1.4","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.4","dist":{"shasum":"cb256244b153dccb9f8c819c33e99fc0cddcd7d5","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.4.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.5":{"name":"express-promise","version":"0.1.5","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.5","dist":{"shasum":"e9b6dd7d08b6e0357bcbad2c62cf19a10ec9155b","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.5.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.6":{"name":"express-promise","version":"0.1.6","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.6","dist":{"shasum":"fda94e73ea421a3b1a7d809e6e03c86ea8ca2fa5","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.6.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.7":{"name":"express-promise","version":"0.1.7","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.7","dist":{"shasum":"4f4c9546811dd0e03c6b34bd5966a0a36249e197","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.7.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.8":{"name":"express-promise","version":"0.1.8","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.8","dist":{"shasum":"7fb614a90b6f0dc33db2c021df216bea4eaeeded","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.8.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.1.9":{"name":"express-promise","version":"0.1.9","scripts":{"test":"mocha -R spec"},"main":"./","licenses":[{"type":"Apache License 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.1.9","dist":{"shasum":"a2901161f2cc4153f2bf048ac0e5f68650da38a4","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.1.9.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"directories":{}},"0.2.0":{"name":"express-promise","version":"0.2.0","scripts":{"test":"mocha -R spec"},"main":"./","licenses":"MIT","homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.2.0","_shasum":"6efeb0271d5b3d60056c1f948b26438d723a8109","_from":".","_npmVersion":"1.4.7","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"dist":{"shasum":"6efeb0271d5b3d60056c1f948b26438d723a8109","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.2.0.tgz"},"directories":{}},"0.3.0":{"name":"express-promise","version":"0.3.0","scripts":{"test":"mocha -R spec"},"main":"./","licenses":"MIT","homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.3.0","_shasum":"b5811b8126bbbfe83cbae2a58461d44e92408e2d","_from":".","_npmVersion":"1.4.7","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"dist":{"shasum":"b5811b8126bbbfe83cbae2a58461d44e92408e2d","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.3.0.tgz"},"directories":{}},"0.4.0":{"name":"express-promise","version":"0.4.0","scripts":{"test":"mocha -R spec"},"main":"./","licenses":"MIT","homepage":"https://github.com/luin/express-promise","repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"engines":["node >=0.6.0"],"keywords":["promise","express","middleware"],"devDependencies":{"mocha":"~1.12.1","should":"~1.2.2","dotq":"~0.1.0"},"gitHead":"161a984aa36c7b2edbb2cf09b04182e2e17fff4d","description":"An [express.js](http://expressjs.com) middleware for easy rendering async query.","bugs":{"url":"https://github.com/luin/express-promise/issues"},"_id":"express-promise@0.4.0","_shasum":"043c3cb7788d0ff299b06506df445722fdfad1e4","_from":".","_npmVersion":"2.0.0","_npmUser":{"name":"luin","email":"i@zihua.li"},"maintainers":[{"name":"luin","email":"i@zihua.li"}],"dist":{"shasum":"043c3cb7788d0ff299b06506df445722fdfad1e4","tarball":"http://registry.npmjs.org/express-promise/-/express-promise-0.4.0.tgz"},"directories":{}}},"readme":"# express-promise\nAn [express.js](http://expressjs.com) middleware for easy rendering async query.\n\n[![Build Status](https://travis-ci.org/luin/express-promise.png?branch=master)](https://travis-ci.org/luin/express-promise)\n\n## Cases\n### 1. previously\n\n app.get('/users/:userId', function(req, res) {\n User.find(req.params.userId).then(function(user) {\n Project.getMemo(req.params.userId).then(function(memo) {\n res.json({\n user: user,\n memo: memo\n });\n });\n });\n });\n\n### 1. now\n\n app.get('/users/:userId', function(req, res) {\n res.json({\n user: User.find(req.params.userId),\n memo: Project.getMemo(req.params.userId)\n });\n });\n\n### 2. previously\n\n app.get('/project/:projectId', function(req, res) {\n var field = req.query.fields.split(';');\n var result = {};\n\n var pending = 0;\n if (field.indexOf('people') !== -1) {\n pending++;\n Project.getField(req.params.projectId).then(function(result) {\n result.people = result;\n if (--pending) {\n output();\n }\n });\n }\n\n if (field.indexOf('tasks') !== -1) {\n pending++;\n Project.getTaskCount(req.params.projectId).then(function(result) {\n result.tasksCount= result;\n if (--pending) {\n output();\n }\n });\n }\n\n function output() {\n res.json(result);\n }\n });\n\n### 2. now\n app.get('/project/:projectId', function(req, res) {\n var field = req.query.fields.split(';');\n var result = {};\n\n if (field.indexOf('people') !== -1) {\n result.people = Project.getField(req.params.projectId);\n }\n\n if (field.indexOf('tasks') !== -1) {\n result.tasksCount = Project.getTaskCount(req.params.projectId);\n }\n\n res.json(result);\n });\n\n## Install\n $ npm install express-promise\n\n## Usage\nJust `app.use` it!\n\n app.use(require('express-promise')());\n\nThis library supports the following methods: `res.send`, `res.json`, `res.render`.\n\nIf you want to let express-promise support nodejs-style callbacks, you can use [dotQ](https://github.com/luin/dotQ) to convert the nodejs-style callbacks to Promises. For example:\n\n require('dotq');\n app.use(require('express-promise')());\n\n var fs = require('fs');\n app.get('/file', function(req, res) {\n res.send(fs.readFile.promise(__dirname + '/package.json', 'utf-8'));\n });\n\n### Skip traverse\n\nAs a gesture to performance, when traverse an object, we call `toJSON` on it to reduce the properties we need to traverse recursively. However that's measure has some negative effects. For instance, all the methods will be removed from the object so you can't use them in the template.\n\nIf you want to skip calling `toJSON` on an object(as well as stop traverse it recursively), you can use the `skipTraverse` option. If the function return `true`, express-promise will skip the object.\n\n app.use(require('express-promise')({\n skipTraverse: function(object) {\n if (object.hasOwnProperty('method')) {\n return true;\n }\n }\n }))\n\n## Libraries\nexpress-promise works well with some ODM/ORM libraries such as [Mongoose](http://mongoosejs.com) and [Sequelize](http://sequelizejs.com). There are some examples in the /examples folder.\n\n### Mongoose\nWhen query a document without passing a callback function, Mongoose will return a [Query](http://mongoosejs.com/docs/queries.html) instance. For example:\n\n var Person = mongoose.model('Person', yourSchema);\n var query = Person.findOne({ 'name.last': 'Ghost' }, 'name occupation');\n\nQuery has a `exec` method, when you call `query.exec(function(err, result) {})`, the query will execute and the result will return to the callback function. In some aspects, Query is like Promise, so express-promise supports Query as well. You can do this:\n\n exports.index = function(req, res){\n res.render('index', {\n title: 'Express',\n cat: Cat.findOne({name: 'Zildjian'})\n });\n };\n\nand in the index.jade, you can use `cat` directly:\n\n p The name of the cat is #{cat.name}\n\n### Sequelize\nSequelize supports Promise after version 1.7.0 :)\n\n## Articles and Recipes\n* [Node Roundup: Bedecked, Knockout.sync.js, express-promise](http://dailyjs.com/2013/09/18/node-roundup/)\n* [减少异步嵌套,Express-promise](http://zihua.li/2013/09/express-promise/) [Chinese]\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2013 Zihua Li\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/luin/express-promise/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n","maintainers":[{"name":"luin","email":"i@zihua.li"}],"time":{"modified":"2014-12-01T04:35:37.263Z","created":"2013-09-04T13:22:16.256Z","0.1.0":"2013-09-04T13:22:25.826Z","0.1.1":"2013-09-04T13:43:11.273Z","0.1.3":"2013-09-04T14:14:18.333Z","0.1.4":"2013-09-05T06:10:24.501Z","0.1.5":"2013-09-05T15:39:18.483Z","0.1.6":"2013-09-05T16:26:54.269Z","0.1.7":"2013-09-05T16:49:00.976Z","0.1.8":"2013-09-09T07:45:38.089Z","0.1.9":"2013-10-01T09:44:47.721Z","0.2.0":"2014-07-15T15:31:06.182Z","0.3.0":"2014-07-31T15:08:34.886Z","0.4.0":"2014-12-01T04:35:37.263Z"},"repository":{"type":"git","url":"git://github.com/luin/express-promise.git"},"users":{"icirellik":true,"tarunbk":true,"danielbankhead":true},"readmeFilename":"README.md","homepage":"https://github.com/luin/express-promise","keywords":["promise","express","middleware"],"bugs":{"url":"https://github.com/luin/express-promise/issues"},"_attachments":{},"_etag":"\"2TBUYY5T8CAIA0EK3RBLEM0W6\""}