{"id":14984,"date":"2025-04-18T21:37:40","date_gmt":"2025-04-18T13:37:40","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/14984.html"},"modified":"2025-04-18T21:37:40","modified_gmt":"2025-04-18T13:37:40","slug":"%e8%ae%a4%e8%af%86-express-%e5%b9%b6%e5%88%9b%e5%bb%ba%e5%9f%ba%e6%9c%ac%e7%9a%84-web-%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/14984.html","title":{"rendered":"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 &#x1f680;<\/li>\n<li>\n<ul>\n<li>1. \u4ec0\u4e48\u662f Express&#xff1f; &#x1f914;<\/li>\n<li>\n<ul>\n<li>1.1 Express \u7684\u7279\u70b9<\/li>\n<\/ul>\n<\/li>\n<li>2. \u5b89\u88c5 Express &#x1f4bb;<\/li>\n<li>\n<ul>\n<li>2.1 \u521d\u59cb\u5316 Node.js \u9879\u76ee<\/li>\n<li>2.2 \u5b89\u88c5 Express<\/li>\n<\/ul>\n<\/li>\n<li>3. \u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 &#x1f5a5;\ufe0f<\/li>\n<li>\n<ul>\n<li>3.1 \u521b\u5efa &#096;app.js&#096;<\/li>\n<li>3.2 \u4ee3\u7801\u89e3\u6790<\/li>\n<li>3.3 \u8fd0\u884c Web \u670d\u52a1\u5668<\/li>\n<\/ul>\n<\/li>\n<li>4. Express \u8def\u7531\u7cfb\u7edf &#x1f6aa;<\/li>\n<li>\n<ul>\n<li>4.1 \u4f7f\u7528\u4e0d\u540c\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5<\/li>\n<li>\n<ul>\n<li>\u793a\u4f8b&#xff1a;\u5904\u7406\u4e0d\u540c HTTP \u65b9\u6cd5\u7684\u8def\u7531<\/li>\n<\/ul>\n<\/li>\n<li>4.2 \u8def\u7531\u53c2\u6570<\/li>\n<li>\n<ul>\n<li>\u793a\u4f8b&#xff1a;\u4f7f\u7528\u8def\u7531\u53c2\u6570<\/li>\n<\/ul>\n<\/li>\n<li>4.3 \u5904\u7406\u67e5\u8be2\u53c2\u6570<\/li>\n<li>\n<ul>\n<li>\u793a\u4f8b&#xff1a;\u5904\u7406\u67e5\u8be2\u53c2\u6570<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>5. \u4e2d\u95f4\u4ef6\u7684\u4f7f\u7528 &#x1f6e0;\ufe0f<\/li>\n<li>\n<ul>\n<li>5.1 \u4f7f\u7528\u5185\u7f6e\u4e2d\u95f4\u4ef6<\/li>\n<li>5.2 \u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6<\/li>\n<li>5.3 \u4f7f\u7528\u4e2d\u95f4\u4ef6\u5904\u7406\u9519\u8bef<\/li>\n<\/ul>\n<\/li>\n<li>6. \u603b\u7ed3 &#x1f3c1;<\/li>\n<li>\n<ul>\n<li>\u4f60\u5df2\u7ecf\u5b66\u5230\u4e86&#xff1a;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 &#x1f680;<\/h2>\n<p>\u5728 Node.js \u4e2d&#xff0c;Express \u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684 Web \u5e94\u7528\u6846\u67b6&#xff0c;\u5b83\u7b80\u5316\u4e86\u6784\u5efa Web \u670d\u52a1\u5668\u548c\u5904\u7406\u8bf7\u6c42\u7684\u8fc7\u7a0b\u3002Express \u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u5927\u7684\u529f\u80fd&#xff0c;\u5982\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u3001\u6a21\u677f\u5f15\u64ce\u652f\u6301\u7b49&#xff0c;\u4f7f\u5f97\u5f00\u53d1 Web \u5e94\u7528\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u548c\u9ad8\u6548\u3002<\/p>\n<p>\u672c\u6587\u5c06\u5e26\u4f60\u8ba4\u8bc6 Express&#xff0c;\u5e76\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u5b83\u6765\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684 Web \u670d\u52a1\u5668\u3002<\/p>\n<h3>1. \u4ec0\u4e48\u662f Express&#xff1f; &#x1f914;<\/h3>\n<p>Express \u662f\u4e00\u4e2a\u57fa\u4e8e Node.js \u5e73\u53f0\u6784\u5efa\u7684 Web \u5e94\u7528\u6846\u67b6&#xff0c;\u5b83\u7b80\u5316\u4e86 Node.js \u4e2d\u539f\u751f HTTP \u6a21\u5757\u7684\u4f7f\u7528&#xff0c;\u8ba9\u4f60\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u521b\u5efa Web \u670d\u52a1\u5668\u548c RESTful API\u3002Express \u63d0\u4f9b\u4e86\u8bb8\u591a\u7528\u4e8e\u5904\u7406 HTTP \u8bf7\u6c42\u3001\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u7b49\u5e38\u89c1\u64cd\u4f5c\u7684\u5de5\u5177&#xff0c;\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91&#xff0c;\u800c\u4e0d\u5fc5\u91cd\u590d\u5b9e\u73b0\u57fa\u7840\u529f\u80fd\u3002<\/p>\n<h4>1.1 Express \u7684\u7279\u70b9<\/h4>\n<ul>\n<li>\u7b80\u6d01\u7684 API&#xff1a;Express \u63d0\u4f9b\u4e86\u7b80\u6d01\u3001\u7075\u6d3b\u7684 API&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u9ad8\u6548\u6784\u5efa Web \u5e94\u7528\u3002<\/li>\n<li>\u4e2d\u95f4\u4ef6\u652f\u6301&#xff1a;Express \u652f\u6301\u4e2d\u95f4\u4ef6&#xff0c;\u5141\u8bb8\u5f00\u53d1\u8005\u5728\u8bf7\u6c42\u548c\u54cd\u5e94\u4e4b\u95f4\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<li>\u8def\u7531\u7cfb\u7edf&#xff1a;\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u8def\u7531\u529f\u80fd&#xff0c;\u80fd\u591f\u6839\u636e HTTP \u8bf7\u6c42\u65b9\u6cd5&#xff08;GET\u3001POST\u3001PUT\u3001DELETE&#xff09;\u548c URL \u8def\u5f84\u5b9a\u4e49\u8def\u7531\u3002<\/li>\n<li>\u6a21\u677f\u5f15\u64ce\u652f\u6301&#xff1a;\u652f\u6301\u591a\u79cd\u6a21\u677f\u5f15\u64ce&#xff08;\u5982 EJS\u3001Pug&#xff09;\u6765\u6e32\u67d3\u52a8\u6001\u7f51\u9875\u3002<\/li>\n<li>\u6269\u5c55\u6027&#xff1a;Express \u5177\u6709\u826f\u597d\u7684\u6269\u5c55\u6027&#xff0c;\u5141\u8bb8\u5f00\u53d1\u8005\u901a\u8fc7\u63d2\u4ef6\u548c\u4e2d\u95f4\u4ef6\u6269\u5c55\u5176\u529f\u80fd\u3002<\/li>\n<\/ul>\n<h3>2. \u5b89\u88c5 Express &#x1f4bb;<\/h3>\n<p>\u9996\u5148&#xff0c;\u6211\u4eec\u9700\u8981\u5b89\u88c5 Express\u3002\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5\u4e86 Node.js \u548c npm&#xff08;Node \u5305\u7ba1\u7406\u5668&#xff09;\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5&#xff0c;\u53ef\u4ee5\u8bbf\u95ee Node.js \u5b98\u7f51 \u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<h4>2.1 \u521d\u59cb\u5316 Node.js \u9879\u76ee<\/h4>\n<p>\u5728\u7ec8\u7aef\u4e2d&#xff0c;\u9996\u5148\u8fdb\u5165\u4f60\u7684\u9879\u76ee\u6587\u4ef6\u5939&#xff0c;\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521d\u59cb\u5316\u4e00\u4e2a Node.js \u9879\u76ee&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> init <span class=\"token parameter variable\">-y<\/span><\/p>\n<p>\u8fd9\u4f1a\u521b\u5efa\u4e00\u4e2a package.json \u6587\u4ef6&#xff0c;\u7528\u4e8e\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u548c\u914d\u7f6e\u3002<\/p>\n<h4>2.2 \u5b89\u88c5 Express<\/h4>\n<p>\u901a\u8fc7 npm \u5b89\u88c5 Express&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> express<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u4f60\u4f1a\u5728 node_modules \u76ee\u5f55\u4e0b\u770b\u5230 express \u5305\u3002<\/p>\n<h3>3. \u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 &#x1f5a5;\ufe0f<\/h3>\n<p>\u5b89\u88c5\u5b8c Express \u540e&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u5f00\u59cb\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 Web \u670d\u52a1\u5668\u4e86\u3002\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684 HTTP \u670d\u52a1\u5668&#xff0c;\u54cd\u5e94\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u3002<\/p>\n<h4>3.1 \u521b\u5efa app.js<\/h4>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6 app.js&#xff0c;\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u5f15\u5165 Express \u6a21\u5757<\/span><br \/>\n<span class=\"token keyword\">const<\/span> express <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">require<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;express&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u521b\u5efa\u4e00\u4e2a Express \u5e94\u7528<\/span><br \/>\n<span class=\"token keyword\">const<\/span> app <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">express<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5b9a\u4e49\u4e00\u4e2a\u8def\u7531&#xff0c;\u54cd\u5e94 GET \u8bf7\u6c42<\/span><br \/>\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;Hello, World!&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u8bbe\u7f6e\u670d\u52a1\u5668\u76d1\u542c\u7684\u7aef\u53e3<\/span><br \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token constant\">PORT<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">3000<\/span><span class=\"token punctuation\">;<\/span><br \/>\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">listen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">PORT<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  console<span class=\"token punctuation\">.<\/span><span class=\"token function\">log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token string\">Server is running at http:\/\/localhost:<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span><span class=\"token constant\">PORT<\/span><span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>3.2 \u4ee3\u7801\u89e3\u6790<\/h4>\n<ul>\n<li>\u5f15\u5165 Express&#xff1a;const express &#061; require(&#039;express&#039;); \u901a\u8fc7 require() \u5f15\u5165 Express \u6a21\u5757\u3002<\/li>\n<li>\u521b\u5efa Express \u5e94\u7528&#xff1a;const app &#061; express(); \u4f7f\u7528 express() \u521b\u5efa\u4e00\u4e2a Express \u5e94\u7528\u5b9e\u4f8b\u3002<\/li>\n<li>\u5b9a\u4e49\u8def\u7531&#xff1a;app.get(&#039;\/&#039;, (req, res) &#061;&gt; {&#8230;}) \u5b9a\u4e49\u4e00\u4e2a GET \u8def\u7531&#xff0c;\u54cd\u5e94\u6839\u8def\u5f84 \/ \u7684\u8bf7\u6c42\u3002req \u662f\u8bf7\u6c42\u5bf9\u8c61&#xff0c;res \u662f\u54cd\u5e94\u5bf9\u8c61&#xff0c;\u6211\u4eec\u901a\u8fc7 res.send() \u8fd4\u56de\u54cd\u5e94\u5185\u5bb9\u3002<\/li>\n<li>\u542f\u52a8\u670d\u52a1\u5668&#xff1a;app.listen(PORT, () &#061;&gt; {&#8230;}) \u542f\u52a8\u670d\u52a1\u5668\u5e76\u76d1\u542c\u6307\u5b9a\u7aef\u53e3&#xff08;\u672c\u4f8b\u4e3a 3000&#xff09;\u3002\u5f53\u670d\u52a1\u5668\u542f\u52a8\u65f6&#xff0c;\u6253\u5370\u670d\u52a1\u5668\u8fd0\u884c\u7684\u5730\u5740\u3002<\/li>\n<\/ul>\n<h4>3.3 \u8fd0\u884c Web \u670d\u52a1\u5668<\/h4>\n<p>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u670d\u52a1\u5668&#xff1a;<\/p>\n<p><span class=\"token function\">node<\/span> app.js<\/p>\n<p>\u6b64\u65f6&#xff0c;\u670d\u52a1\u5668\u4f1a\u542f\u52a8\u5e76\u76d1\u542c\u5728 http:\/\/localhost:3000\u3002\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u8bbf\u95ee\u8be5\u5730\u5740&#xff0c;\u4f60\u5e94\u8be5\u80fd\u591f\u770b\u5230 Hello, World! \u7684\u54cd\u5e94\u3002<\/p>\n<h3>4. Express \u8def\u7531\u7cfb\u7edf &#x1f6aa;<\/h3>\n<p>Express \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u8def\u7531\u529f\u80fd&#xff0c;\u652f\u6301\u5904\u7406\u4e0d\u540c\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5&#xff08;\u5982 GET\u3001POST\u3001PUT\u3001DELETE&#xff09;\u4ee5\u53ca\u8def\u7531\u53c2\u6570\u3002<\/p>\n<h4>4.1 \u4f7f\u7528\u4e0d\u540c\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5<\/h4>\n<p>Express \u5141\u8bb8\u6211\u4eec\u4e3a\u4e0d\u540c\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5\u5b9a\u4e49\u8def\u7531\u3002\u5e38\u89c1\u7684\u65b9\u6cd5\u6709&#xff1a;<\/p>\n<ul>\n<li>GET&#xff1a;\u7528\u4e8e\u8bf7\u6c42\u83b7\u53d6\u8d44\u6e90&#xff08;\u5e38\u7528\u4e8e\u8bfb\u53d6\u6570\u636e&#xff09;\u3002<\/li>\n<li>POST&#xff1a;\u7528\u4e8e\u63d0\u4ea4\u6570\u636e&#xff08;\u5e38\u7528\u4e8e\u63d0\u4ea4\u8868\u5355\u3001\u521b\u5efa\u8d44\u6e90&#xff09;\u3002<\/li>\n<li>PUT&#xff1a;\u7528\u4e8e\u66f4\u65b0\u8d44\u6e90\u3002<\/li>\n<li>DELETE&#xff1a;\u7528\u4e8e\u5220\u9664\u8d44\u6e90\u3002<\/li>\n<\/ul>\n<h5>\u793a\u4f8b&#xff1a;\u5904\u7406\u4e0d\u540c HTTP \u65b9\u6cd5\u7684\u8def\u7531<\/h5>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;This is a GET request&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">post<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;This is a POST request&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">put<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;This is a PUT request&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">delete<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;This is a DELETE request&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5\u6765\u8bbf\u95ee\u8fd9\u4e9b\u8def\u7531&#xff0c;\u8868\u8fbe\u4e0d\u540c\u7684\u64cd\u4f5c\u3002<\/p>\n<h4>4.2 \u8def\u7531\u53c2\u6570<\/h4>\n<p>Express \u652f\u6301\u5728\u8def\u7531\u4e2d\u5b9a\u4e49\u52a8\u6001\u53c2\u6570&#xff0c;\u8fd9\u5bf9\u4e8e\u6784\u5efa RESTful API \u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982&#xff0c;\u4f60\u53ef\u4ee5\u901a\u8fc7 URL \u8def\u5f84\u53c2\u6570\u6765\u83b7\u53d6\u8bf7\u6c42\u7684\u7279\u5b9a\u8d44\u6e90\u3002<\/p>\n<h5>\u793a\u4f8b&#xff1a;\u4f7f\u7528\u8def\u7531\u53c2\u6570<\/h5>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/user\/:id&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> userId <span class=\"token operator\">&#061;<\/span> req<span class=\"token punctuation\">.<\/span>params<span class=\"token punctuation\">.<\/span>id<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u83b7\u53d6\u8def\u5f84\u53c2\u6570<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token string\">User ID: <\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span>userId<span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5982\u679c\u4f60\u8bbf\u95ee http:\/\/localhost:3000\/user\/123&#xff0c;\u670d\u52a1\u5668\u4f1a\u8fd4\u56de User ID: 123\u3002<\/p>\n<h4>4.3 \u5904\u7406\u67e5\u8be2\u53c2\u6570<\/h4>\n<p>\u67e5\u8be2\u53c2\u6570\u901a\u5e38\u7528\u4e8e\u4f20\u9012\u989d\u5916\u7684\u67e5\u8be2\u4fe1\u606f&#xff0c;\u683c\u5f0f\u4e3a ?key&#061;value\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7 req.query \u8bbf\u95ee\u67e5\u8be2\u53c2\u6570\u3002<\/p>\n<h5>\u793a\u4f8b&#xff1a;\u5904\u7406\u67e5\u8be2\u53c2\u6570<\/h5>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/search&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> query <span class=\"token operator\">&#061;<\/span> req<span class=\"token punctuation\">.<\/span>query<span class=\"token punctuation\">.<\/span>q<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u83b7\u53d6\u67e5\u8be2\u53c2\u6570 q<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token string\">Search query: <\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span>query<span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8bbf\u95ee http:\/\/localhost:3000\/search?q&#061;Node.js \u65f6&#xff0c;\u670d\u52a1\u5668\u4f1a\u8fd4\u56de Search query: Node.js\u3002<\/p>\n<h3>5. \u4e2d\u95f4\u4ef6\u7684\u4f7f\u7528 &#x1f6e0;\ufe0f<\/h3>\n<p>Express \u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5176\u652f\u6301\u4e2d\u95f4\u4ef6&#xff08;middleware&#xff09;\u3002\u4e2d\u95f4\u4ef6\u662f\u7528\u4e8e\u5904\u7406\u8bf7\u6c42\u3001\u54cd\u5e94\u7684\u51fd\u6570&#xff0c;\u4f4d\u4e8e\u8bf7\u6c42\u548c\u54cd\u5e94\u4e4b\u95f4\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e2d\u95f4\u4ef6\u6765\u8fdb\u884c\u65e5\u5fd7\u8bb0\u5f55\u3001\u8ba4\u8bc1\u3001\u89e3\u6790\u8bf7\u6c42\u4f53\u7b49\u64cd\u4f5c\u3002<\/p>\n<h4>5.1 \u4f7f\u7528\u5185\u7f6e\u4e2d\u95f4\u4ef6<\/h4>\n<p>Express \u63d0\u4f9b\u4e86\u591a\u4e2a\u5185\u7f6e\u4e2d\u95f4\u4ef6&#xff0c;\u6bd4\u5982 express.json()\u3001express.urlencoded()&#xff0c;\u7528\u4e8e\u89e3\u6790\u8bf7\u6c42\u4f53\u3002<\/p>\n<p><span class=\"token comment\">\/\/ \u89e3\u6790 JSON \u8bf7\u6c42\u4f53<\/span><br \/>\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<\/span><span class=\"token punctuation\">(<\/span>express<span class=\"token punctuation\">.<\/span><span class=\"token function\">json<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u89e3\u6790 URL \u7f16\u7801\u7684\u8bf7\u6c42\u4f53<\/span><br \/>\napp<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<\/span><span class=\"token punctuation\">(<\/span>express<span class=\"token punctuation\">.<\/span><span class=\"token function\">urlencoded<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token literal-property property\">extended<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">true<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>5.2 \u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6<\/h4>\n<p>\u4f60\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002\u4f8b\u5982&#xff0c;\u8bb0\u5f55\u8bf7\u6c42\u65e5\u5fd7&#xff1a;<\/p>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  console<span class=\"token punctuation\">.<\/span><span class=\"token function\">log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span>req<span class=\"token punctuation\">.<\/span>method<span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token string\"> <\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span>req<span class=\"token punctuation\">.<\/span>url<span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token function\">next<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8c03\u7528\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>next() \u7528\u4e8e\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531\u3002\u5982\u679c\u6ca1\u6709\u8c03\u7528 next()&#xff0c;\u8bf7\u6c42\u5c06\u4e0d\u4f1a\u7ee7\u7eed\u5904\u7406\u3002<\/p>\n<h4>5.3 \u4f7f\u7528\u4e2d\u95f4\u4ef6\u5904\u7406\u9519\u8bef<\/h4>\n<p>\u9519\u8bef\u5904\u7406\u4e2d\u95f4\u4ef6\u9700\u8981\u6709\u56db\u4e2a\u53c2\u6570&#xff1a;err, req, res, next\u3002Express \u4f1a\u5728\u9047\u5230\u9519\u8bef\u65f6\u81ea\u52a8\u8c03\u7528\u5b83\u3002<\/p>\n<p>app<span class=\"token punctuation\">.<\/span><span class=\"token function\">use<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">err<span class=\"token punctuation\">,<\/span> req<span class=\"token punctuation\">,<\/span> res<span class=\"token punctuation\">,<\/span> next<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  console<span class=\"token punctuation\">.<\/span><span class=\"token function\">error<\/span><span class=\"token punctuation\">(<\/span>err<span class=\"token punctuation\">.<\/span>stack<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  res<span class=\"token punctuation\">.<\/span><span class=\"token function\">status<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">500<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;Something went wrong!&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h3>6. \u603b\u7ed3 &#x1f3c1;<\/h3>\n<p>Express \u662f\u4e00\u4e2a\u5f3a\u5927\u4e14\u7075\u6d3b\u7684 Web \u5e94\u7528\u6846\u67b6&#xff0c;\u5b83\u8ba9\u5f00\u53d1 Web \u670d\u52a1\u5668\u548c API \u53d8\u5f97\u7b80\u5355\u3002\u901a\u8fc7\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u3001\u6a21\u677f\u5f15\u64ce\u7b49\u529f\u80fd&#xff0c;Express \u63d0\u4f9b\u4e86\u6784\u5efa\u73b0\u4ee3 Web \u5e94\u7528\u6240\u9700\u7684\u6240\u6709\u57fa\u7840\u8bbe\u65bd\u3002<\/p>\n<h4>\u4f60\u5df2\u7ecf\u5b66\u5230\u4e86&#xff1a;<\/h4>\n<ul>\n<li>\u5982\u4f55\u5b89\u88c5\u548c\u4f7f\u7528 Express\u3002<\/li>\n<li>\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684 Web \u670d\u52a1\u5668\u5e76\u5904\u7406 HTTP \u8bf7\u6c42\u3002<\/li>\n<li>\u5982\u4f55\u4f7f\u7528\u8def\u7531\u6765\u5904\u7406\u4e0d\u540c\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5\u548c\u8def\u5f84\u3002<\/li>\n<li>\u5982\u4f55\u4f7f\u7528\u4e2d\u95f4\u4ef6\u6765\u6269\u5c55\u5e94\u7528\u7684\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p>\u5e0c\u671b\u4f60\u901a\u8fc7\u672c\u6587\u5bf9 Express \u6709\u4e86\u66f4\u6df1\u5165\u7684\u4e86\u89e3&#xff0c;\u5e76\u80fd\u5728\u81ea\u5df1\u7684\u9879\u76ee\u4e2d\u5e94\u7528\u8fd9\u4e9b\u6280\u672f&#xff0c;\u6784\u5efa\u66f4\u5f3a\u5927\u3001\u66f4\u7075\u6d3b\u7684 Web \u5e94\u7528&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf25\u6b21\u3002Express \u662f\u4e00\u4e2a\u57fa\u4e8e Node.js \u5e73\u53f0\u6784\u5efa\u7684 Web \u5e94\u7528\u6846\u67b6\uff0c\u5b83\u7b80\u5316\u4e86 Node.js \u4e2d\u539f\u751f HTTP \u6a21\u5757\u7684\u4f7f\u7528\uff0c\u8ba9\u4f60\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u521b\u5efa Web \u670d\u52a1\u5668\u548c RESTful API\u3002Express \u63d0\u4f9b\u4e86\u8bb8\u591a\u7528\u4e8e\u5904\u7406 HTTP \u8bf7\u6c42\u3001\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u7b49\u5e38\u89c1\u64cd\u4f5c\u7684\u5de5\u5177\uff0c\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91\uff0c\u800c\u4e0d\u5fc5\u91cd\u590d\u5b9e\u73b0\u57fa\u7840\u529f\u80fd\u3002\u4f60\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002${next();\/\/ \u8c03\u7528\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531 });next();\/\/ \u8c03\u7528\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531 });next();_\u670d\u52a1\u5668\u7aef express<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[573,709,965,964,187,87,43,727],"topic":[],"class_list":["post-14984","post","type-post","status-publish","format-standard","hentry","category-server","tag-css","tag-express","tag-firefox","tag-html5","tag-javascript","tag-87","tag-43","tag-727"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/14984.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf25\u6b21\u3002Express \u662f\u4e00\u4e2a\u57fa\u4e8e Node.js \u5e73\u53f0\u6784\u5efa\u7684 Web \u5e94\u7528\u6846\u67b6\uff0c\u5b83\u7b80\u5316\u4e86 Node.js \u4e2d\u539f\u751f HTTP \u6a21\u5757\u7684\u4f7f\u7528\uff0c\u8ba9\u4f60\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u521b\u5efa Web \u670d\u52a1\u5668\u548c RESTful API\u3002Express \u63d0\u4f9b\u4e86\u8bb8\u591a\u7528\u4e8e\u5904\u7406 HTTP \u8bf7\u6c42\u3001\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u7b49\u5e38\u89c1\u64cd\u4f5c\u7684\u5de5\u5177\uff0c\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91\uff0c\u800c\u4e0d\u5fc5\u91cd\u590d\u5b9e\u73b0\u57fa\u7840\u529f\u80fd\u3002\u4f60\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002${next();\/\/ \u8c03\u7528\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531 });next();\/\/ \u8c03\u7528\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531 });next();_\u670d\u52a1\u5668\u7aef express\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/14984.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T13:37:40+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/14984.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/14984.html\",\"name\":\"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T13:37:40+00:00\",\"dateModified\":\"2025-04-18T13:37:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/14984.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/14984.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/14984.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/14984.html","og_locale":"zh_CN","og_type":"article","og_title":"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf25\u6b21\u3002Express \u662f\u4e00\u4e2a\u57fa\u4e8e Node.js \u5e73\u53f0\u6784\u5efa\u7684 Web \u5e94\u7528\u6846\u67b6\uff0c\u5b83\u7b80\u5316\u4e86 Node.js \u4e2d\u539f\u751f HTTP \u6a21\u5757\u7684\u4f7f\u7528\uff0c\u8ba9\u4f60\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u521b\u5efa Web \u670d\u52a1\u5668\u548c RESTful API\u3002Express \u63d0\u4f9b\u4e86\u8bb8\u591a\u7528\u4e8e\u5904\u7406 HTTP \u8bf7\u6c42\u3001\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u7b49\u5e38\u89c1\u64cd\u4f5c\u7684\u5de5\u5177\uff0c\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91\uff0c\u800c\u4e0d\u5fc5\u91cd\u590d\u5b9e\u73b0\u57fa\u7840\u529f\u80fd\u3002\u4f60\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u4e2d\u95f4\u4ef6\u51fd\u6570\u3002${next();\/\/ \u8c03\u7528\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531 });next();\/\/ \u8c03\u7528\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u8def\u7531 });next();_\u670d\u52a1\u5668\u7aef express","og_url":"https:\/\/www.wsisp.com\/helps\/14984.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T13:37:40+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/14984.html","url":"https:\/\/www.wsisp.com\/helps\/14984.html","name":"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T13:37:40+00:00","dateModified":"2025-04-18T13:37:40+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/14984.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/14984.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/14984.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u8ba4\u8bc6 Express \u5e76\u521b\u5efa\u57fa\u672c\u7684 Web \u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/14984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=14984"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/14984\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=14984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=14984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=14984"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=14984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}