diff --git a/examples/co.js b/examples/co.js new file mode 100644 index 0000000..3ba50f4 --- /dev/null +++ b/examples/co.js @@ -0,0 +1,22 @@ + +var koa = require('..'); +var fs = require('co-fs'); +var app = koa(); + +// read docs/*.md in parallel +// and return a joined response + +app.use(function(){ + return function *(){ + var paths = yield fs.readdir('docs'); + + var files = yield paths.map(function(path){ + return fs.readFile('docs/' + path, 'utf8'); + }); + + this.type = 'markdown'; + this.body = files.join(', '); + } +}); + +app.listen(3000); diff --git a/package.json b/package.json index 4324c64..220810d 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "rack" ], "repository": "koajs/koa", - "author": "", "license": "MIT", "dependencies": { "co": "1.5.1", @@ -35,7 +34,8 @@ "bytes": "*", "should": "1.2.2", "mocha": "1.12.0", - "supertest": "0.7.1" + "supertest": "0.7.1", + "co-fs": "~1.0.1" }, "engines": { "node": "> 0.11.4"