express-coroutine Express 中使用 Generator 方法

程序名称:express-coroutine

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

express-coroutine 介绍

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

安装:

npm install express-coroutine --save

初始化:

// Init express

const express = require('express-coroutine')(require('express'));
const app = express();

// Init router

const express = require('express-coroutine')(require('express'));
const app = express();
const router = new expressGenerators.Router();
app.use(router);

router.get('/', function* (req, res) {
  res.send('it works!');
});

使用:

const express = require('express-coroutine')(require('express'));

const app = express();

app.get('/user/:id', function* (req, res) {
  const user = yield User.findById(req.params.id);
  res.send(user);
})

app.get('/error', function* (req, res) {
  throw new Error('Bang!');
});

app.listen(8000);

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

express-coroutine 官网

https://git.oschina.net/yourtion/express-coroutine

相关编程语言

MuPlayer 是一款跨平台、轻量级的音频播放解决方案,...
OS FLV 是一个 开源和可嵌入网页的flv播放器。 这个...
DewPlayer音乐播放器,样式很简单,而且很实用.播放器...
JW FLV MEDIA PLAYER是一个开源的在网页上使用的Fla...
Speakker 是一个基于 Web 浏览器的音乐播放器,只提...
Player Framework 是一个开源的支持 HTML5 的视频播...