{"id":942,"date":"2020-03-01T23:39:40","date_gmt":"2020-03-01T15:39:40","guid":{"rendered":"https:\/\/www.bluesdream.com\/blog\/?p=942"},"modified":"2020-03-05T17:26:15","modified_gmt":"2020-03-05T09:26:15","slug":"express-koa-framework-comparison","status":"publish","type":"post","link":"https:\/\/www.bluesdream.com\/blog\/express-koa-framework-comparison.html","title":{"rendered":"Express \u548c Koa \u6846\u67b6\u5bf9\u6bd4"},"content":{"rendered":"<blockquote><p>\n  \u4eca\u5e743\u6708\uff0c\u53ef\u4ee5\u8bf4\u662f2020\u5e74\u7684\u201c\u65b0\u201d\u8d77\u70b9\uff0c\u8d81\u7740\u75ab\u60c5\u671f\u95f4\uff0c\u5bf9\u8fc7\u5f80\u548c\u672a\u6765\u6280\u672f\u65b9\u5411\u505a\u4e2a\u5c0f\u6574\u7406\u3002\n<\/p><\/blockquote>\n<p><a href=\"https:\/\/expressjs.com\/\">Express<\/a> \u51e0\u4e4e\u4e0e Node.js \u4e00\u6837\u8001\uff0c\u4e5f\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684 Node.js web\u5e94\u7528\u6846\u67b6\uff0c\u5f88\u591a\u5e94\u7528\u6846\u67b6\u4e5f\u662f\u57fa\u4e8e Express \u6784\u5efa\u3002<a href=\"https:\/\/koajs.com\/\">Koa<\/a> \u5219\u5c5e\u4e8e\u540e\u8d77\u4e4b\u79c0\uff0c\u8fd1\u5e74\u6765\u5728\u56fd\u5185\u6bd4\u8f83\u70ed\u95e8\u4e14\u4e3b\u6d41\u7684\u6846\u67b6\u4e4b\u4e00\u3002\u4e24\u8005\u90fd\u53ef\u8f7b\u677e\u7684\u521b\u5efa REST APIs\u3001\u9759\u6001\u670d\u52a1\u5668\u7b49\uff0c\u672c\u6587\u4e3b\u8981\u5c31\u62ff\u8fd9\u4e24\u4e2a\u6846\u67b6\u8fdb\u884c\u5bf9\u6bd4\u3002<\/p>\n<blockquote><p>\n  \u5f53\u7136\u8fd8\u6709\uff1a<code>Hapi<\/code>\u3001<code>Egg.js<\/code>\u3001<code>Nest.js<\/code> \u7b49\u6846\u67b6\uff0c\u5728\u6587\u7ae0\u7ed3\u5c3e\u4f1a\u7b80\u5355\u4ecb\u7ecd\uff0c\u7531\u4e8e\u5e76\u4e3a\u5b9e\u9645\u4f7f\u7528\uff0c\u6240\u4ee5\u4e0d\u5728\u672c\u6587\u8ba8\u8bba\u8303\u56f4\uff0c\u4ec5\u4f5c\u4e3a\u6269\u5c55\u5185\u5bb9\u53bb\u7406\u89e3\u3002\n<\/p><\/blockquote>\n<p><!--more--><\/p>\n<h2>\u57fa\u672c\u4ecb\u7ecd\uff1a<\/h2>\n<h3>Express:<\/h3>\n<blockquote><p>\n  Fast, unopinionated, minimalist web framework for node.\uff08\u9ad8\u5ea6\u5305\u5bb9\u3001\u5feb\u901f\u800c\u6781\u7b80\u7684 Node.js Web \u6846\u67b6\u3002\uff09\n<\/p><\/blockquote>\n<p>Express \u662f\u9488\u5bf9 Node.js \u7684Web\u5e94\u7528\u6846\u67b6\u3002\u4e3a Web \u548c\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e00\u7ec4\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5e76\u4fdd\u6301\u6700\u4f4e\u7a0b\u5ea6\u89c4\u6a21\u7684\u7075\u6d3b\u3002<br \/>\n\u7531 TJ Holowaychuk \u521b\u7acb\uff0c\u9996\u6b21\u63d0\u4ea4\u4e8e 2010\u5e74\u7b2c\u4e8c\u5b63\u5ea6\uff0c2014\u5e74\u88ab StrongLoop \u6536\u8d2d\uff0c2016\u5e74 StrongLoop \u53c8\u88ab IBM \u5e76\u8d2d\uff0c\u76ee\u524d\u7f6e\u4e8e Node.js \u57fa\u91d1\u4f1a\u5b75\u5316\u5668\u7684\u7ba1\u7406\u4e4b\u4e0b\u3002<br \/>\nExpress \u5185\u7f6e\u8def\u7531\u548c\u6a21\u7248\uff0c\u5f00\u7bb1\u5373\u7528\u3002<\/p>\n<h3>Koa:<\/h3>\n<blockquote><p>\n  Expressive middleware for node.js using ES2017 async functions.\uff08\u4f7f\u7528 ES2017 \u5f02\u6b65\u51fd\u6570\u5904\u7406 Node.js \u4e2d\u95f4\u4ef6\u3002\uff09\n<\/p><\/blockquote>\n<p>Koa \u7531 Express \u540c\u4e00\u56e2\u961f\u5f00\u53d1\uff0c\u4f5c\u4e3a\u4e0b\u4e00\u4ee3 Web \u6846\u67b6\uff0c\u66f4\u73b0\u4ee3\u548c\u8f7b\u91cf\u3002<br \/>\n\u9996\u6b21\u63d0\u4ea4\u4e8e 2013\u5e74\u5e95\uff0c\u66f4\u4e3a\u5e74\u8f7b\uff0c\u652f\u6301\u66f4\u73b0\u4ee3\u7684 ES6\/7\/8 \u8bed\u6cd5\u3002<br \/>\nKoa \u4e0d\u63d0\u4f9b\u5185\u7f6e\u8def\u7531\u7b49\u548c\u4efb\u4f55\u4e2d\u95f4\u4ef6\uff0c\u66f4\u52a0\u7b80\u5316\u3002<\/p>\n<blockquote><p>\n  \u56e0\u4e3a\u4f7f\u7528 ES6 \u7279\u6027\uff0c\u6240\u4ee5\u9700\u8981 Node v7.6.0+ \u7248\u672c\u7684\u652f\u6301\u3002\n<\/p><\/blockquote>\n<h2>\u6570\u636e\u7edf\u8ba1\uff1a<\/h2>\n<p>\u4ee5\u4e0b\u6570\u636e\uff0c\u57fa\u4e8e 2020-02-29 \u5404\u81ea\u7684 NPM \u9879\u76ee\u4e3b\u9875\u3002<\/p>\n<h3>Express:<\/h3>\n<ul>\n<li>Current Version: <code>4.17.1<\/code><\/li>\n<li>Weekly Downloads: <code>11,886,941<\/code><\/li>\n<li>Github Stars: <code>47.5k<\/code><\/li>\n<li>Unpacked Size: <code>208 kB<\/code><\/li>\n<li>Last publish: <code>9 months ago<\/code><\/li>\n<\/ul>\n<h3>Koa:<\/h3>\n<ul>\n<li>Current Version: <code>2.11.0<\/code><\/li>\n<li>Weekly Downloads: <code>409,189<\/code><\/li>\n<li>Github Stars: <code>28.6k<\/code><\/li>\n<li>Unpacked Size: <code>83.8 kB<\/code><\/li>\n<li>Last publish: <code>4 months ago<\/code><\/li>\n<\/ul>\n<h2>\u57fa\u7840\u793a\u4f8b\uff1a<\/h2>\n<p>\u5f00\u53d1 Node.js \u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7b2c\u4e00\u6b65\u5c31\u662f\u521b\u5efa\u4e00\u4e2a\u6700\u57fa\u672c\u7684\u670d\u52a1\u5668\u3002<\/p>\n<h3>Express:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst express = require(&#039;express&#039;)\nconst app = express()\napp.listen(3000, () =&gt; console.log(&#039;App is listening on port 3000!&#039;))\n<\/pre>\n<p>\u6b64\u5904\u7684 app.listen() \u5176\u5b9e\u662f http.createServer() \u7684\u8bed\u6cd5\u7cd6\u3002<\/p>\n<h3>Koa:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst Koa = require(&#039;koa&#039;)\nconst app = new Koa()\napp.listen(3000, () =&gt; console.log(&#039;App is listening on port 3000!&#039;))\n<\/pre>\n<p>Koa \u7684 app.listen()  \u540c\u6837\u4e5f\u662f http.createServer() \u7684\u8bed\u6cd5\u7cd6\u3002\u4f46\u8bf7\u6ce8\u610f\u7b2c\u4e00\u884c\u7684 Koa \u662f\u5927\u5199\uff0c\u56e0\u4e3a\u5bfc\u5165\u7684\u662f\u4e00\u4e2a class \u7c7b\u3002<\/p>\n<h3>\u7b80\u8ff0\uff1a<\/h3>\n<p>\u4ece\u4e2d\u53ef\u4ee5\u53d1\u73b0 Koa \u4e0e Express \u5341\u5206\u76f8\u4f3c\uff0c\u57fa\u7840\u7528\u6cd5\u51e0\u4e4e\u4e00\u6837\u3002<\/p>\n<h2>\u4e2d\u95f4\u4ef6\uff1a<\/h2>\n<p>\u4e2d\u95f4\u4ef6\u662f\u4f4d\u4e8e <code>\u8bf7\u6c42\u5bf9\u8c61(Request)<\/code>  \u548c <code>\u54cd\u5e94\u5bf9\u8c61(Response)<\/code> \u4e4b\u95f4\u7684\u51fd\u6570\u3002<code>next()<\/code> \u53ef\u4ee5\u653e\u884c\u4e2d\u95f4\u4ef6\uff0c\u5141\u8bb8\u6267\u4e0b\u4e00\u6761\u547d\u4ee4\uff0c\u5426\u5219\u5f53\u524d\u4e2d\u95f4\u4ef6\u51fd\u6570\u6ca1\u6709 <code>\u7ed3\u675f\u8bf7\u6c42\/\u54cd\u5e94\u5faa\u73af<\/code> \u65f6\uff0c\u90a3\u4e48\u8bf7\u6c42\u5c06\u4fdd\u6301 <code>\u6302\u8d77\u72b6\u6001<\/code>\uff0c\u5bfc\u81f4<code>\u540e\u7eed\u547d\u4ee4\u65e0\u6cd5\u6267\u884c<\/code>\u3002<\/p>\n<h3>Express:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst express = require(&#039;express&#039;)\nconst app = express()\napp.use((req, res, next) =&gt; {\n  console.log(`Time: ${Date.now()}`)\n  next()\n})\napp.listen(3000)\n<\/pre>\n<p>\u901a\u8fc7 app.use() \u6ce8\u518c\uff0c\u5c06\u4e2d\u95f4\u4ef6\u7ed1\u5b9a\u5230 app \u5bf9\u8c61\u3002<\/p>\n<h3>Koa:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst Koa = require(&#039;koa&#039;)\nconst app = new Koa()\napp.use(async (ctx, next) =&gt; {\n  console.log(`Time: ${Date.now()}`)\n  await next()\n})\napp.listen(3000)\n<\/pre>\n<p>\u4e2d\u95f4\u4ef6\u6ce8\u518c\u7c7b\u4f3c Express\uff0c\u4f46\u589e\u52a0\u4e86 <code>\u4e0a\u4e0b\u6587\u5bf9\u8c61(Context)<\/code>\uff0c\u53ef\u4ee5\u628a\u5355\u6b21\u8bf7\u6c42\u76f8\u5173\u7684\u4e0a\u4e0b\u6587\u5168\u6302\u8f7d\u4e0a\u53bb\uff0c\u6bd4 <code>\u8bf7\u6c42\u5bf9\u8c61(Request)<\/code> \u548c <code>\u54cd\u5e94\u5bf9\u8c61(Response)<\/code> \u66f4\u52a0\u7684\u8bed\u4e49\u5316\uff0c\u5bf9\u4e8e\u4efb\u4f55\u8bf7\u6c42\u4e5f\u90fd\u5c06\u7528\u66f4\u73b0\u4ee3\u7684 <code>async<\/code> \u51fd\u6570\u3002<\/p>\n<h3>\u7b80\u8ff0\uff1a<\/h3>\n<p>\u4e24\u8005\u7684\u6838\u5fc3\u4e2d\u95f4\u4ef6\uff0c\u5206\u522b\u662f\uff1a<a href=\"https:\/\/github.com\/expressjs\/compression\/blob\/master\/index.js\">compression<\/a> \u548c <a href=\"https:\/\/github.com\/koajs\/compress\/blob\/master\/index.js\">koa-compress<\/a> \uff0c\u901a\u8fc7\u6e90\u7801\u53ef\u4ee5\u53d1\u73b0 Koa \u901a\u8fc7 Promise \u65b9\u6cd5\u66f4\u4e3a\u7cbe\u7b80\uff0c\u51cf\u5c11\u4e86\u56de\u8c03\u7684\u5904\u7406\u3002\u5728 Koa \u4e2d\uff0c\u4e00\u5207\u6d41\u7a0b\u90fd\u662f\u4e2d\u95f4\u4ef6\uff0c\u6570\u636e\u6d41\u5411\u9075\u5faa\u6d0b\u8471\u6a21\u578b\uff0c\u7c7b\u4f3c\u5806\u6808\u7684\u5148\u5165\u540e\u51fa\u539f\u5219\u3002<\/p>\n<h2>\u57fa\u672c\u8def\u7531\uff1a<\/h2>\n<p>\u8def\u7531\u662f\u670d\u52a1\u5668\u7684\u91cd\u8981\u7279\u6027\u4e4b\u4e00\uff0c\u9996\u5148\u4e3a\u4e24\u4e2a\u6846\u67b6\u521b\u5efa\u4e00\u4e2a\u8001\u5957\u7684 \"Hello world\" \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h3>Express:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst express = require(&#039;express&#039;)\nconst app = express()\nconst router = express.Router()\nrouter.get(&#039;\/hello&#039;, (req, res, next) =&gt; {\n  res.send(&#039;Hello World!&#039;)\n})\nrouter.get(&#039;\/hello\/:name&#039;, (req, res, next) =&gt; {\n  let name = req.params.name\n  res.send(`Hello, ${name}!`)\n})\napp.use(&#039;\/&#039;, router)\napp.listen(3000, () =&gt; {\n  console.log(`listening on *: ${3000}`)\n})\n<\/pre>\n<p>Express \u53ef\u4ee5\u4f7f\u7528 <code>app.get()<\/code> \u65b9\u6cd5\u6765\u83b7\u53d6 GET \u53c2\u6570\uff0c\u5176\u8bed\u6cd5\u4e3a <code>app.METHOD(PATH, HANDLER)<\/code>\u3002\u901a\u8fc7\u56de\u8c03\u51fd\u6570\u6765\u5904\u7406 <code>\u8bf7\u6c42(req)<\/code> \u548c <code>\u54cd\u5e94(res)<\/code>\u3002\u5176\u5185\u7f6e\u7684\u8def\u7531\u65b9\u6cd5\uff0c\u8fd8\u5305\u62ec <code>app.post()<\/code>\u3001<code>app.delete()<\/code>\u7b49\u3002<\/p>\n<p>\u4f46\u66f4\u63a8\u8350\u4f7f\u7528\u5185\u7f6e\u7684 <code>express.Router<\/code> \uff0c\u53ef\u4ee5\u5c06\u4e2d\u95f4\u4ef6\u4e0e\u8def\u7531\u8fdb\u884c\u5206\u79bb\uff0c\u80fd\u4e3a\u4e0d\u540c\u5e94\u7528\u5185\u7f6e\u4e00\u4e2a\u5355\u72ec\u7684\u5e94\u7528\u8def\u7531\u3002<\/p>\n<h3>Koa:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst Koa = require(&#039;koa&#039;)\nconst Router = require(&#039;koa-router&#039;)\nconst app = new Koa()\nconst router = new Router()\nrouter.get(&#039;\/hello&#039;, (ctx, next) =&gt; {\n  ctx.body = &#039;Hello World!&#039;\n})\nrouter.get(&#039;\/hello\/:name&#039;, (ctx, next) =&gt; {\n    let name = ctx.params.name;\n    ctx.response.body = `Hello, ${name}!`\n});\napp.use(router.routes())\napp.listen(3000)\n<\/pre>\n<p>Koa \u4e0e Express \u7565\u6709\u4e0d\u540c\uff0c\u56e0\u4e3a\u6ca1\u6709\u5185\u7f6e\u4efb\u4f55\u4e2d\u95f4\u4ef6\uff0c\u9700\u8981\u989d\u5916\u5b89\u88c5 <code>koa-router<\/code> \u4f9d\u8d56\u3002<\/p>\n<h3>\u7b80\u8ff0\uff1a<\/h3>\n<p>\u4e24\u8005\u8bbe\u8ba1\u98ce\u683c\u975e\u5e38\u63a5\u8fd1\uff0c\u5e95\u5c42\u4e5f\u90fd\u662f\u5171\u7528\u7684\u540c\u4e00\u5957 <code>HTTP \u57fa\u7840\u5e93<\/code>\u3002<\/p>\n<h2>POST\u8bf7\u6c42\u548c\u54cd\u5e94<\/h2>\n<p>POST \u8bf7\u6c42\u4e5f\u662f\u6700\u5e38\u7528\u7684\u8bf7\u6c42\u4e4b\u4e00\uff0c\u4e24\u8005\u5206\u522b\u9700\u8981\u989d\u5916\u5b89\u88c5 <code>body-parser<\/code> \u548c <code>koa-bodyparser<\/code> \u4f9d\u8d56\uff0c\u5bf9\u8bf7\u6c42\u4f53\u8fdb\u884c\u89e3\u6790\u3002<\/p>\n<h3>Express:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst express = require(&#039;express&#039;)\nconst bodyParser = require(&#039;body-parser&#039;)\nconst app = express()\nconst router = express.Router()\napp.use(bodyParser())\nrouter.post(&#039;\/api&#039;, async (req, res, next) =&gt; {\n  try {\n    await next()\n    res.json(req.body)\n  } catch (error) {\n    res.json(error)\n  }\n})\napp.use(&#039;\/&#039;, router)\napp.listen(3000)\n<\/pre>\n<h3>Koa:<\/h3>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nconst Koa = require(&#039;koa&#039;)\nconst Router = require(&#039;koa-router&#039;)\nconst bodyParser = require(&#039;koa-bodyparser&#039;)\nconst app = new Koa()\nconst router = new Router()\napp.use(bodyParser())\nrouter.post(&#039;\/api&#039;, async (ctx, next) =&gt; {\n  try {\n    await next()\n    ctx.response.body = ctx.request.body\n  } catch (error) {\n    ctx.response.body = error\n  }\n})\napp.use(router.routes())\napp.listen(3000)\n<\/pre>\n<h3>\u7b80\u8ff0<\/h3>\n<p>\u4e24\u4e2a\u7684\u8bf7\u6c42\u5730\u5740\u540c\u4e3a <code>http:\/\/localhost:3000\/api\/<\/code>\u3002\u540c\u65f6\u53ef\u4ee5\u53d1\u73b0 Express \u4e5f\u53ef\u4ee5\u652f\u6301 <code>async\/await<\/code> \u51fd\u6570\uff0c\u56e0\u4e3a <code>Node.js 7+<\/code> \u5df2\u7ecf\u539f\u751f\u652f\u6301\uff0c\u4e5f\u80fd\u6709\u6548\u7684\u907f\u514d<code>\u5730\u72f1\u56de\u8c03<\/code>\u3002<\/p>\n<p>\u73b0\u5728 Node \u5df2\u7ecf 12.x\uff0c\u5bf9 ES \u7684\u652f\u6301\u5ea6\u4e5f\u63d0\u9ad8\u4e0d\u5c11\u3002\u5404\u7248\u672c\u5177\u4f53\u5bf9 ES6 \u7684\u652f\u6301\u7a0b\u5ea6\uff0c\u53ef\u5728\u6b64\u67e5\u770b\uff1a<a href=\"https:\/\/node.green\/\">https:\/\/node.green\/<\/a><\/p>\n<h2>\u4f18\u70b9\uff1a<\/h2>\n<h3>Express:<\/h3>\n<ul>\n<li>\u7b80\u5355\u4e14\u5feb\u901f\u7684\u5f00\u53d1\u5e94\u7528\u3002<\/li>\n<li>\u62e5\u6709\u5e9e\u5927\u7684\u751f\u6001\uff0c\u652f\u6301\u66f4\u591a\u7684\u7b2c\u4e09\u65b9\u63d2\u4ef6\u3002<\/li>\n<li>\u793e\u533a\u66f4\u52a0\u6210\u719f\uff0c\u610f\u5473\u7740\u6709\u66f4\u591a\u652f\u6301\u4e0e\u6587\u6863\u53ef\u4ee5\u67e5\u9605\u3002<\/li>\n<li>\u5b66\u4e60\u66f2\u7ebf\u4f4e\u3002<\/li>\n<\/ul>\n<h3>Koa:<\/h3>\n<ul>\n<li>\u66f4\u8f7b\u91cf\uff0c\u66f4\u5065\u58ee\u3002<\/li>\n<li>\u5bf9 ES2017 \u7684\u652f\u6301\u3002<\/li>\n<li>\u53ef\u4ee5\u81ea\u5df1\u5f00\u53d1\u4e2d\u95f4\u4ef6\uff0c\u66f4\u7075\u6d3b\uff0c\u81ea\u7531\u5ea6\u9ad8\u3002<\/li>\n<li>\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u7ef4\u62a4\u6027\u66f4\u9ad8\u3002<\/li>\n<\/ul>\n<h2>\u7f3a\u70b9\uff1a<\/h2>\n<h3>Express:<\/h3>\n<ul>\n<li>\u9700\u8981\u6e05\u6670\u7684\u7ec4\u7ec7\u7ed3\u6784\uff0c\u5426\u5219\u540e\u671f\u7ef4\u62a4\u96be\u5ea6\u56f0\u96be\u3002<\/li>\n<li>\u4ee3\u7801\u5e93\u8d8a\u5927\uff0c\u91cd\u6784\u96be\u5ea6\u8d8a\u5927\u3002<\/li>\n<li>\u9700\u8981\u521b\u5efa\u6240\u6709\u8282\u70b9\u3002<\/li>\n<li>\u6ca1\u6709\u5185\u7f6e\u9519\u8bef\u5904\u7406\u3002<\/li>\n<\/ul>\n<h3>Koa:<\/h3>\n<ul>\n<li>\u793e\u533a\u76f8\u5bf9\u8f83\u5c0f\uff0c\u610f\u5473\u7740\u652f\u6301\u4e0e\u6587\u6863\u4e5f\u4f1a\u8f83\u5c11\u3002<\/li>\n<li>\u4e0e Express \u98ce\u683c\u7684\u4e2d\u95f4\u4ef6\u4e0d\u517c\u5bb9\u3002<\/li>\n<li>Koa \u7684\u7279\u5b9a\u4e2d\u95f4\u4ef6\u4e0e\u5176\u4ed6\u6846\u67b6\u4e0d\u517c\u5bb9\u3002<\/li>\n<\/ul>\n<h2>\u603b\u7ed3\uff1a<\/h2>\n<p>\u4ece 17 \u5e74\u5f00\u59cb\uff0c\u5c31\u6709 Koa \u4f55\u65f6\u4f1a\u8d85\u8d8a Express \u7684\u8ba8\u8bba\uff0c\u867d\u7136 Koa \u786e\u5b9e\u5728\u8fc5\u901f\u589e\u957f\uff0c\u5c31\u76ee\u524d\u770b\u6765\u8fd8\u662f\u6709\u5f88\u957f\u4e00\u6bb5\u8def\u8981\u8d70\u3002<\/p>\n<p>\u6700\u521d Express \u7531\u4e8e\u4e0d\u652f\u6301 ES6\uff0c\u5730\u72f1\u56de\u8c03\u95ee\u9898\u8ba9\u4eba\u7740\u5b9e\u5934\u75bc\uff0c\u4f46\u968f\u7740 Node \u7248\u672c\u66f4\u65b0\uff0c\u5bf9 ES \u7684\u652f\u6301\u5ea6\u63d0\u5347\uff0c\u4e24\u8005\u7684\u5dee\u8ddd\u4e5f\u5728\u7f29\u5c0f\u3002\u53e6\u5916\uff0c <code>Express 5.0 alpha<\/code> \u7b2c\u4e00\u7248\u5df2\u7ecf\u53d1\u5e03\uff0c\u5bf9\u90e8\u5206 API \u8fdb\u884c\u4e86\u8c03\u6574\uff0c\u4f46\u5c31\u66f4\u65b0\u9891\u7387\u6765\u770b\uff0cKoa \u660e\u663e\u8981\u5927\u4e8e Express\u3002<\/p>\n<p>Express \u5bf9\u4e2d\u5c0f\u578b\u9879\u76ee\u6765\u8bf4\uff0c\u4ecd\u7136\u662f\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u5bf9\u5927\u578b\u9879\u76ee\u6765\u8bf4\u9700\u8981\u524d\u671f\u826f\u597d\u7684\u89c4\u5212\u548c\u6a21\u5757\u5316\uff0c\u5426\u5219\u7ba1\u7406\u8d77\u6765\u96be\u5ea6\u4f1a\u8d8a\u6765\u8d8a\u5927\u3002<\/p>\n<p>Koa \u66f4\u9002\u5408\u521d\u5b66\u8005\uff0c\u662f\u4e00\u4e2a\u8f7b\u91cf\u5316\u7684\u57fa\u7840\u6846\u67b6\uff0c\u53ef\u4ee5\u4ece\u96f6\u5f00\u59cb\u642d\u5efa\uff0c\u4ee3\u7801\u7ba1\u7406\u66f4\u4e3a\u5bb9\u6613\uff0c\u9519\u8bef\u5904\u7406\u8d77\u6765\u66f4\u65b9\u4fbf\uff0c\u9002\u5408\u654f\u6377\u5f00\u53d1\u3002<\/p>\n<p>\u6700\u7ec8\u7684\u9009\u62e9\uff0c\u8fd8\u662f\u4e00\u8d2f\u7b56\u7565\uff0c\u53d6\u51b3\u4e8e\u9879\u76ee\u9700\u6c42\u548c\u56e2\u961f\u60c5\u51b5\u3002<\/p>\n<h2>\u6269\u5c55\uff1a<\/h2>\n<p><strong><a href=\"https:\/\/hapi.dev\/\">Hapi<\/a><\/strong><br \/>\n\u7531 Walmart Labs \u56e2\u961f\u5f00\u53d1\uff0c\u6700\u521d\u8be5\u56e2\u961f\u662f\u57fa\u4e8e Express\uff0c\u4f46\u7531\u4e8e\u65e0\u6cd5\u6ee1\u8db3\u4ed6\u4eec\u7684\u540e\u7eed\u9700\u6c42\u4e4b\u540e\uff0c\u4fbf\u5f00\u53d1\u4e86\u6b64\u6846\u67b6\uff08Github Stars: 12.1k\uff0cWeekly Downloads: 250,000+\uff09\u3002<\/p>\n<p><strong><a href=\"https:\/\/eggjs.org\/\">Egg.js<\/a><\/strong><br \/>\n\u7531\u963f\u91cc\u57fa\u4e8e Koa \u5f00\u53d1\u7684\u6846\u67b6\uff0c\u5728 Koa \u7684\u6a21\u578b\u57fa\u7840\u4e0a\uff0c\u8fdb\u4e00\u6b65\u5bf9\u5b83\u8fdb\u884c\u4e86\u4e00\u4e9b\u589e\u5f3a\uff08Github Stars: 28.6k\uff0cWeekly Downloads: 5,000+\uff09\u3002<\/p>\n<p><strong><a href=\"https:\/\/nestjs.com\/\">Nest.js<\/a><\/strong><br \/>\n\u6e10\u8fdb\u5f0f Node.js \u6846\u67b6\uff0c\u53ef\u4ee5\u5728TypeScript\u548cJavaScript (ES6\u3001ES7\u3001ES8)\u4e4b\u4e0a\u9ad8\u6548\u6784\u5efa\u3002\u5728 2019\u5e74 JavaScript \u660e\u661f\u9879\u76ee Node.js \u6846\u67b6\u7ec4\u5185\uff0c\u70b9\u8d5e\u589e\u957f\u6570\u4f4d\u5217\u7b2c\u4e00\uff08Github Stars: 24.7k\uff0cWeekly Downloads: 70,000+\uff09\u3002<\/p>\n<h2>\u53c2\u8003\u6587\u7ae0\uff1a<\/h2>\n<p><a href=\"https:\/\/www.stackchief.com\/blog\/Koa%20vs%20Express%20\">Koa vs Express<\/a><br \/>\n<a href=\"https:\/\/www.airpair.com\/node.js\/posts\/nodejs-framework-comparison-express-koa-hapi\">Is Express the Best Option?<\/a><br \/>\n<a href=\"https:\/\/medium.com\/@mklum88\/is-express-the-best-option-c5990ac9232e\">Node.js Framework Comparison: Express vs. Koa vs. Hapi<\/a><br \/>\n<a href=\"https:\/\/nodesource.com\/blog\/Express-Koa-Hapi\">Choosing the right Node.js Framework: Express, Koa, or Hapi?<\/a><br \/>\n<a href=\"https:\/\/www.sitepoint.com\/express-koa-hapi\/\">A Side-by-side Comparison of Express, Koa and Hapi.js<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5e743\u6708\uff0c\u53ef\u4ee5\u8bf4\u662f2020\u5e74\u7684\u201c\u65b0\u201d\u8d77\u70b9\uff0c\u8d81\u7740\u75ab\u60c5\u671f\u95f4\uff0c\u5bf9\u8fc7\u5f80\u548c\u672a\u6765\u6280\u672f\u65b9\u5411\u505a\u4e2a\u5c0f\u6574\u7406\u3002 Express \u51e0\u4e4e\u4e0e Node.js \u4e00\u6837\u8001\uff0c\u4e5f\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684 Node.js web\u5e94\u7528\u6846\u67b6\uff0c\u5f88\u591a\u5e94\u7528\u6846\u67b6\u4e5f\u662f\u57fa\u4e8e Express \u6784\u5efa\u3002Koa \u5219\u5c5e\u4e8e\u540e\u8d77\u4e4b\u79c0\uff0c\u8fd1\u5e74\u6765\u5728\u56fd\u5185\u6bd4\u8f83\u70ed\u95e8\u4e14\u4e3b\u6d41\u7684\u6846\u67b6\u4e4b\u4e00\u3002\u4e24\u8005\u90fd\u53ef\u8f7b\u677e\u7684\u521b\u5efa REST APIs\u3001\u9759\u6001\u670d\u52a1\u5668\u7b49\uff0c\u672c\u6587\u4e3b\u8981\u5c31\u62ff\u8fd9\u4e24\u4e2a\u6846\u67b6\u8fdb\u884c\u5bf9\u6bd4\u3002 \u5f53\u7136\u8fd8\u6709\uff1aHapi\u3001Egg.js\u3001Nest.js \u7b49\u6846\u67b6\uff0c\u5728\u6587\u7ae0\u7ed3\u5c3e\u4f1a\u7b80\u5355\u4ecb\u7ecd\uff0c\u7531\u4e8e\u5e76\u4e3a\u5b9e\u9645\u4f7f\u7528\uff0c\u6240\u4ee5\u4e0d\u5728\u672c\u6587\u8ba8\u8bba\u8303\u56f4\uff0c\u4ec5\u4f5c\u4e3a\u6269\u5c55\u5185\u5bb9\u53bb\u7406\u89e3\u3002<\/p>\n","protected":false},"author":1,"featured_media":945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[188,189,135,190,191],"class_list":["post-942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-front-end","tag-express","tag-koa","tag-nodejs","tag-190","tag-191"],"_links":{"self":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/942"}],"collection":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/comments?post=942"}],"version-history":[{"count":0,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media\/945"}],"wp:attachment":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media?parent=942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/categories?post=942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/tags?post=942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}