express-coroutine Express 中使用 Generator 方法

我要开发同款
匿名用户2017年03月01日
146阅读

技术信息

授权协议
MIT

作品详情

在Express中像Koa那样使用Geerator方法。

安装:

pm istall express-coroutie --save

初始化:

// Iit expresscost express = require('express-coroutie')(require('express'));cost app = express();// Iit routercost express = require('express-coroutie')(require('express'));cost app = express();cost router = ew expressGeerators.Router();app.use(router);router.get('/', fuctio* (req, res) {  res.sed('it works!');});

使用:

cost express = require('express-coroutie')(require('express'));cost app = express();app.get('/user/:id', fuctio* (req, res) {  cost user = yield User.fidById(req.params.id);  res.sed(user);})app.get('/error', fuctio* (req, res) {  throw ew Error('Bag!');});app.liste(8000);

更多用法详见测试文件:https://github.com/yourtio/express-coroutie/blob/master/test.js

功能介绍

在 Express 中像 Koa 那样使用 Generator 方法。 安装: npm install express-coroutine --save 初始化: // Init express...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论