{"id":21688,"date":"2025-04-19T04:57:27","date_gmt":"2025-04-18T20:57:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/21688.html"},"modified":"2025-04-19T04:57:27","modified_gmt":"2025-04-18T20:57:27","slug":"node-js%e5%90%af%e5%8a%a8express-http-%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%bf%9e%e6%8e%a5%e6%9c%ac%e5%9c%b0%e6%95%b0%e6%8d%ae%e5%ba%93%e4%bb%a5%e5%8f%8a%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/21688.html","title":{"rendered":"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09"},"content":{"rendered":"<p>&#x1f923;\u76f8\u4fe1\u5927\u5bb6\u7528nodejs\u8dd1\u901a\u8fc7\u540e\u7aef\u548c\u524d\u7aef\u5b8c\u6210\u4ea4\u4e92\u7684\u8fc7\u7a0b\u540e\u90fd\u6709\u8fd9\u4e48\u4e00\u4e2a\u7591\u95ee&#xff0c;emmmmmmmm\u53cd\u6b63\u6211\u662f\u8fd9\u6837&#xff0c;\u524d\u7aef&#xff08;\u5ba2\u6237\u7aef&#xff09;\u548c\u540e\u7aef&#xff08;\u670d\u52a1\u7aef&#xff09;\u662f\u5177\u4f53\u5982\u4f55\u8fdb\u884c\u4ea4\u4e92\u7684&#xff0c;\u4e3a\u4ec0\u4e48\u6211\u524d\u7aef\u5411\u53d1\u9001\u540e\u7aef\u53d1\u9001\u4e86\u4e00\u4e2a\u8bf7\u6c42\u80fd\u88ab\u540e\u7aef\u63a5\u53d7\u5230&#xff0c;\u63a5\u4e0b\u6765\u6211\u8be6\u7ec6\u8bb2\u4e00\u4e0b\u5305\u62ec\u5982\u4f55\u5b9e\u73b0\u524d\u540e\u7aef\u4ea4\u4e92\u548c\u5176\u4e2d\u7684\u539f\u7406\u3002\n <\/p>\n<p>&#xff08;\u6709\u9519\u8bf7\u60a8\u7ea0\u9519&#xff0c;\u8bf4\u7684\u4e0d\u8be6\u7ec6\u7684\u90e8\u5206\u53ef\u4ee5\u8bc4\u8bba\u6211\u5c3d\u91cf\u5b8c\u5584&#xff09;<\/p>\n<p>\u53c2\u8003\u6587\u7ae0&#xff1a;\u4e00\u6587\u6559\u4f60\u7528Uniapp\u8fde\u63a5\u672c\u5730MySQL\u6570\u636e\u5e93_uniapp mysql-CSDN\u535a\u5ba2<\/p>\n<p>\u4f46\u662f\u7528\u4ec0\u4e48IDE\u5f00\u53d1\u5bf9<\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE-toc\" style=\"margin-left:0px\">\u73af\u5883\u914d\u7f6e<\/p>\n<p id=\"%E6%96%87%E4%BB%B6%E8%A7%A3%E6%9E%90-toc\" style=\"margin-left:0px\">\u6587\u4ef6\u89e3\u6790<\/p>\n<p id=\"%E5%B1%9E%E6%80%A7-toc\" style=\"margin-left:80px\">\u5c5e\u6027<\/p>\n<p id=\"%E6%96%B9%E6%B3%95-toc\" style=\"margin-left:80px\">\u65b9\u6cd5<\/p>\n<p id=\"HTTP%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%92%8C%20Express%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E5%85%B3%E7%B3%BB-toc\" style=\"margin-left:80px\">HTTP \u670d\u52a1\u5668\u548c Express \u670d\u52a1\u5668\u7684\u5173\u7cfb<\/p>\n<p id=\"%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">\u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE\">\u73af\u5883\u914d\u7f6e<\/h2>\n<p>1.\u9996\u5148&#xff0c;\u5728\u9879\u76ee\u6587\u4ef6\u4e2d\u8fd0\u884c\u00a0npm install express-generator -g\u00a0&#xff0c;\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5168\u5c40\u5b89\u88c5\u00a0Express \u5e94\u7528\u751f\u6210\u5668&#xff08;express-generator&#xff09;\u3002\u8fd9\u662f\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177&#xff0c;\u53ef\u4ee5\u5feb\u901f\u751f\u6210\u4e00\u4e2a Express \u5e94\u7528\u7684\u9aa8\u67b6\u4ee3\u7801&#xff0c;\u5e2e\u52a9\u4f60\u5feb\u901f\u542f\u52a8\u9879\u76ee\u3002 \u5b89\u88c5\u6210\u529f\u540e&#xff0c;\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0express\u00a0\u547d\u4ee4\u6765\u751f\u6210 Express \u5e94\u7528<\/p>\n<p>npm install express-generator -g<\/p>\n<p>2.\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p>express &#8211;view&#061;ejs server<\/p>\n<ul>\n<li>-view&#061;ejs&#xff1a;\u6307\u5b9a\u4f7f\u7528 EJS \u4f5c\u4e3a\u6a21\u677f\u5f15\u64ce\u3002<\/li>\n<li>server&#xff1a;\u9879\u76ee\u540d\u79f0&#xff0c;\u751f\u6210\u7684\u6587\u4ef6\u5939\u540d\u79f0<\/li>\n<\/ul>\n<p>\u751f\u6210\u7684\u6587\u4ef6\u5982\u4e0b\u6240\u793a<\/p>\n<p>server\/<br \/>\n\u251c\u2500\u2500 bin\/<br \/>\n\u2502   \u2514\u2500\u2500 www              # \u542f\u52a8\u811a\u672c<br \/>\n\u251c\u2500\u2500 public\/              # \u9759\u6001\u6587\u4ef6&#xff08;CSS\u3001JS\u3001\u56fe\u7247\u7b49&#xff09;<br \/>\n\u251c\u2500\u2500 routes\/              # \u8def\u7531\u6587\u4ef6<br \/>\n\u2502   \u251c\u2500\u2500 index.js         # \u6839\u8def\u7531<br \/>\n\u2502   \u2514\u2500\u2500 users.js         # \u7528\u6237\u8def\u7531<br \/>\n\u251c\u2500\u2500 views\/               # \u89c6\u56fe\u6587\u4ef6&#xff08;EJS \u6a21\u677f&#xff09;<br \/>\n\u2502   \u251c\u2500\u2500 error.ejs        # \u9519\u8bef\u9875\u9762<br \/>\n\u2502   \u2514\u2500\u2500 index.ejs        # \u9996\u9875<br \/>\n\u251c\u2500\u2500 app.js               # \u5e94\u7528\u4e3b\u6587\u4ef6<br \/>\n\u251c\u2500\u2500 package.json         # \u9879\u76ee\u4f9d\u8d56\u548c\u914d\u7f6e<br \/>\n\u2514\u2500\u2500 package-lock.json    # \u4f9d\u8d56\u9501\u6587\u4ef6<\/p>\n<p>3.\u5728server\u6587\u4ef6\u4e2d\u5b89\u88c5\u4f9d\u8d56<\/p>\n<p>\u00a0npm install<\/p>\n<p>npm install\u00a0\u547d\u4ee4\u4f1a\u5b89\u88c5\u5f53\u524d\u9879\u76ee\u4e2d\u00a0package.json\u00a0\u6587\u4ef6\u91cc\u5b9a\u4e49\u7684\u6240\u6709\u4f9d\u8d56\u5305<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;MySQL \u5305\u4f1a\u88ab\u6dfb\u52a0\u5230\u00a0package.json\u00a0\u7684\u00a0dependencies\u00a0\u5b57\u6bb5\u4e2d<\/p>\n<p>4.\u56de\u5230\u5728\u7b2c\u4e00\u6b65\u521b\u5efa\u7684\u76ee\u5f55\u4e2d<\/p>\n<p>npm init -y<br \/>\nnpm i mysql <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;MySQL \u5305\u4f1a\u88ab\u6dfb\u52a0\u5230\u00a0package.json\u00a0\u7684\u00a0dependencies\u00a0\u5b57\u6bb5\u4e2d\u3002\u5728\u6b64\u57fa\u7840\u4e0a\u53ef\u4ee5\u5b89\u88c5mysql\u7b49\u5404\u79cd\u5e93<\/p>\n<p>5.\u8fd0\u884c<\/p>\n<p>npm start<\/p>\n<p>\u6700\u540e\u7684\u6587\u4ef6\u5982\u56fe\u6240\u793a&#xff08;\u6ca1\u6709.env\u8fd9\u4e2a\u6211\u81ea\u5df1\u52a0\u7684&#xff09;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"312\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418205726-6802bcb676574.png\" width=\"362\" \/><\/p>\n<hr \/>\n<h2 id=\"%E6%96%87%E4%BB%B6%E8%A7%A3%E6%9E%90\">\u6587\u4ef6\u89e3\u6790<\/h2>\n<p>\u6838\u5fc3\u6587\u4ef6&#xff1a;<\/p>\n<p>1.bin\/www<\/p>\n<p>#!\/usr\/bin\/env node<\/p>\n<p>\/**<br \/>\n * \u5f15\u5165\u4f9d\u8d56\u6a21\u5757<br \/>\n *\/<\/p>\n<p>var app &#061; require(&#039;..\/app&#039;);\/\/ \u5f15\u5165 Express \u5e94\u7528<br \/>\nvar debug &#061; require(&#039;debug&#039;)(&#039;server:server&#039;);<br \/>\nvar http &#061; require(&#039;http&#039;);<\/p>\n<p>\/**<br \/>\n * \u8bbe\u7f6e\u7aef\u53e3<br \/>\n *\/<\/p>\n<p>var port &#061; normalizePort(process.env.PORT || &#039;3000&#039;);<br \/>\napp.set(&#039;port&#039;, port);<\/p>\n<p>\/**<br \/>\n * \u521b\u5efa HTTP \u670d\u52a1\u5668<br \/>\n *\/<\/p>\n<p>var server &#061; http.createServer(app);<\/p>\n<p>\/**<br \/>\n * \u76d1\u542c\u7aef\u53e3<br \/>\n *\/<\/p>\n<p>server.listen(port);<br \/>\nserver.on(&#039;error&#039;, onError);<br \/>\nserver.on(&#039;listening&#039;, onListening);<\/p>\n<p>\/**<br \/>\n * Normalize a port into a number, string, or false.<br \/>\n *\/<\/p>\n<p>function normalizePort(val) {<br \/>\n  var port &#061; parseInt(val, 10);<\/p>\n<p>  if (isNaN(port)) {<br \/>\n    \/\/ named pipe<br \/>\n    return val;<br \/>\n  }<\/p>\n<p>  if (port &gt;&#061; 0) {<br \/>\n    \/\/ port number<br \/>\n    return port;<br \/>\n  }<\/p>\n<p>  return false;<br \/>\n}<\/p>\n<p>\/**<br \/>\n * Event listener for HTTP server &#034;error&#034; event.<br \/>\n *\/<\/p>\n<p>function onError(error) {<br \/>\n  if (error.syscall !&#061;&#061; &#039;listen&#039;) {<br \/>\n    throw error;<br \/>\n  }<\/p>\n<p>  var bind &#061; typeof port &#061;&#061;&#061; &#039;string&#039;<br \/>\n    ? &#039;Pipe &#039; &#043; port<br \/>\n    : &#039;Port &#039; &#043; port;<\/p>\n<p>  \/\/ handle specific listen errors with friendly messages<br \/>\n  switch (error.code) {<br \/>\n    case &#039;EACCES&#039;:<br \/>\n      console.error(bind &#043; &#039; requires elevated privileges&#039;);<br \/>\n      process.exit(1);<br \/>\n      break;<br \/>\n    case &#039;EADDRINUSE&#039;:<br \/>\n      console.error(bind &#043; &#039; is already in use&#039;);<br \/>\n      process.exit(1);<br \/>\n      break;<br \/>\n    default:<br \/>\n      throw error;<br \/>\n  }<br \/>\n}<\/p>\n<p>\/**<br \/>\n * Event listener for HTTP server &#034;listening&#034; event.<br \/>\n *\/<\/p>\n<p>function onListening() {<br \/>\n  var addr &#061; server.address();<br \/>\n  var bind &#061; typeof addr &#061;&#061;&#061; &#039;string&#039;<br \/>\n    ? &#039;pipe &#039; &#043; addr<br \/>\n    : &#039;port &#039; &#043; addr.port;<br \/>\n  debug(&#039;Listening on &#039; &#043; bind);<br \/>\n}<\/p>\n<p>\u603b\u4e4b&#xff0c;\u8be5\u6587\u4ef6\u662f Express \u5e94\u7528\u7684\u542f\u52a8\u811a\u672c&#xff0c;\u901a\u5e38\u4f4d\u4e8e\u00a0bin\/www\u00a0\u6587\u4ef6\u4e2d\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u542f\u52a8 HTTP \u670d\u52a1\u5668\u5e76\u76d1\u542c\u6307\u5b9a\u7aef\u53e3&#xff0c;\u8be5\u811a\u672c\u6587\u4ef6\u5f00\u5934\u8c03\u7528\u4e86..app\u8fd9\u4e2a\u6587\u4ef6<\/p>\n<p>2.app.js<\/p>\n<p>var createError &#061; require(&#039;http-errors&#039;);<br \/>\nvar express &#061; require(&#039;express&#039;);<br \/>\nvar path &#061; require(&#039;path&#039;);<br \/>\nvar cookieParser &#061; require(&#039;cookie-parser&#039;);<br \/>\nvar logger &#061; require(&#039;morgan&#039;);<\/p>\n<p>var indexRouter &#061; require(&#039;.\/routes\/index&#039;);<br \/>\nvar usersRouter &#061; require(&#039;.\/routes\/users&#039;);<\/p>\n<p>var app &#061; express();<\/p>\n<p>\/\/ view engine setup<br \/>\napp.set(&#039;views&#039;, path.join(__dirname, &#039;views&#039;));<br \/>\napp.set(&#039;view engine&#039;, &#039;ejs&#039;);<\/p>\n<p>app.use(logger(&#039;dev&#039;));<br \/>\napp.use(express.json());<br \/>\napp.use(express.urlencoded({ extended: false }));<br \/>\napp.use(cookieParser());<br \/>\napp.use(express.static(path.join(__dirname, &#039;public&#039;)));<\/p>\n<p>app.use(&#039;\/&#039;, indexRouter);<br \/>\napp.use(&#039;\/users&#039;, usersRouter);<\/p>\n<p>\/\/ catch 404 and forward to error handler<br \/>\napp.use(function(req, res, next) {<br \/>\n  next(createError(404));<br \/>\n});<\/p>\n<p>\/\/ error handler<br \/>\napp.use(function(err, req, res, next) {<br \/>\n  \/\/ set locals, only providing error in development<br \/>\n  res.locals.message &#061; err.message;<br \/>\n  res.locals.error &#061; req.app.get(&#039;env&#039;) &#061;&#061;&#061; &#039;development&#039; ? err : {};<\/p>\n<p>  \/\/ render the error page<br \/>\n  res.status(err.status || 500);<br \/>\n  res.render(&#039;error&#039;);<br \/>\n});<\/p>\n<p>module.exports &#061; app;<\/p>\n<ul>\n<li>\u8fd9\u6bb5\u4ee3\u7801\u5b8c\u6210\u4e86\u4e00\u4e2a Express \u5e94\u7528\u7684\u57fa\u672c\u914d\u7f6e&#xff0c;\u5305\u62ec&#xff1a;\n<ul>\n<li>\u5f15\u5165\u4f9d\u8d56\u6a21\u5757\u3002<\/li>\n<li>\u8bbe\u7f6e\u89c6\u56fe\u5f15\u64ce\u548c\u9759\u6001\u6587\u4ef6\u76ee\u5f55\u3002<\/li>\n<li>\u914d\u7f6e\u4e2d\u95f4\u4ef6&#xff08;\u65e5\u5fd7\u3001\u8bf7\u6c42\u4f53\u89e3\u6790\u3001Cookie \u89e3\u6790\u7b49&#xff09;\u3002<\/li>\n<li>\u5b9a\u4e49\u8def\u7531\u3002<\/li>\n<li>\u5904\u7406 404 \u9519\u8bef\u548c\u5168\u5c40\u9519\u8bef\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u901a\u8fc7\u8fd0\u884c\u6b64\u6587\u4ef6&#xff0c;\u53ef\u4ee5\u542f\u52a8\u4e00\u4e2a Express \u670d\u52a1\u5668&#xff0c;\u5904\u7406 HTTP \u8bf7\u6c42\u5e76\u8fd4\u56de\u54cd\u5e94\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u6587\u4ef6\u5728\u6700\u540e\u00a0app\u00a0\u5bf9\u8c61&#xff0c;\u4f9b\u5176\u4ed6\u6a21\u5757&#xff08;\u5982\u00a0bin\/www&#xff09;\u4f7f\u7528&#xff0c;<\/p>\n<p>app\u00a0\u5bf9\u8c61\u662f\u00a0express()\u00a0\u51fd\u6570\u7684\u8fd4\u56de\u503c&#xff0c;\u5b83\u662f\u4e00\u4e2a Express \u5e94\u7528\u5b9e\u4f8b&#xff0c;\u5177\u6709\u4ee5\u4e0b\u6838\u5fc3\u5c5e\u6027\u548c\u65b9\u6cd5&#xff1a;<\/p>\n<h4 id=\"%E5%B1%9E%E6%80%A7\">\u5c5e\u6027<\/h4>\n<ul>\n<li>app.settings&#xff1a;\u5b58\u50a8\u5e94\u7528\u7684\u914d\u7f6e\u9879&#xff0c;\u4f8b\u5982&#xff1a;\n<ul>\n<li>views&#xff1a;\u89c6\u56fe\u6587\u4ef6\u76ee\u5f55&#xff08;\u901a\u8fc7\u00a0app.set(&#039;views&#039;, path.join(__dirname, &#039;views&#039;))\u00a0\u8bbe\u7f6e&#xff09;\u3002<\/li>\n<li>view engine&#xff1a;\u89c6\u56fe\u5f15\u64ce&#xff08;\u901a\u8fc7\u00a0app.set(&#039;view engine&#039;, &#039;ejs&#039;)\u00a0\u8bbe\u7f6e&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>app.locals&#xff1a;\u5e94\u7528\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u53ef\u4ee5\u5728\u6240\u6709\u89c6\u56fe\u4e2d\u8bbf\u95ee\u3002<\/li>\n<li>app._router&#xff1a;\u5b58\u50a8\u8def\u7531\u548c\u4e2d\u95f4\u4ef6\u7684\u5806\u6808\u3002<\/li>\n<\/ul>\n<h4 id=\"%E6%96%B9%E6%B3%95\">\u65b9\u6cd5<\/h4>\n<ul>\n<li>app.use()&#xff1a;\u52a0\u8f7d\u4e2d\u95f4\u4ef6\u6216\u8def\u7531\u3002<\/li>\n<li>app.set()&#xff1a;\u8bbe\u7f6e\u5e94\u7528\u7684\u914d\u7f6e\u9879\u3002<\/li>\n<li>app.get()&#xff1a;\u83b7\u53d6\u914d\u7f6e\u9879\u7684\u503c\u6216\u5b9a\u4e49\u8def\u7531\u3002<\/li>\n<li>app.listen()&#xff1a;\u542f\u52a8\u670d\u52a1\u5668\u5e76\u76d1\u542c\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p>\u5728\u00a0bin\/www\u00a0\u4e2d&#xff0c;app\u00a0\u5bf9\u8c61\u4f1a\u88ab\u4f20\u9012\u7ed9\u00a0http.createServer()&#xff0c;\u7528\u4e8e\u542f\u52a8 HTTP \u670d\u52a1\u5668\u3002<\/p>\n<p>\u603b\u4e4b&#xff0c;\u524d\u9762\u90a3\u4e9b\u6587\u4ef6\u548c\u5404\u79cd\u8c03\u7528\u6700\u540e\u5b8c\u6210\u7684\u5c31\u662f\u542f\u52a8\u4e00\u4e2a Express \u670d\u52a1\u5668&#xff0c;\u5b83\u5904\u7406 HTTP \u8bf7\u6c42\u5e76\u8fd4\u56de\u54cd\u5e94&#xff08;\u4e2a\u4eba\u7406\u89e3\u6709\u610f\u89c1\u53ef\u6307\u51fa&#xff09;<\/p>\n<h4 id=\"HTTP%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%92%8C%20Express%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E5%85%B3%E7%B3%BB\">HTTP \u670d\u52a1\u5668\u548c Express \u670d\u52a1\u5668\u7684\u5173\u7cfb<\/h4>\n<ul>\n<li>Express \u57fa\u4e8e HTTP \u670d\u52a1\u5668&#xff1a;\n<ul>\n<li>Express \u662f\u5bf9 HTTP \u670d\u52a1\u5668\u7684\u5c01\u88c5&#xff0c;\u5e95\u5c42\u4ecd\u7136\u4f7f\u7528 Node.js \u7684\u00a0http\u00a0\u6a21\u5757\u3002<\/li>\n<li>\u5728 Express \u4e2d&#xff0c;app.listen()\u00a0\u5b9e\u9645\u4e0a\u8c03\u7528\u4e86\u00a0http.createServer()\u3002<\/li>\n<\/ul>\n<\/li>\n<li>Express \u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684\u62bd\u8c61&#xff1a;\n<ul>\n<li>Express \u7b80\u5316\u4e86\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u3001\u9519\u8bef\u5904\u7406\u7b49\u529f\u80fd\u7684\u5b9e\u73b0\u3002<\/li>\n<li>\u5f00\u53d1\u8005\u53ef\u4ee5\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91&#xff0c;\u800c\u4e0d\u9700\u8981\u5173\u5fc3\u5e95\u5c42\u7684 HTTP \u7ec6\u8282\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"%E6%80%BB%E7%BB%93\">\u603b\u7ed3<\/h2>\n<p>\u8c03\u7528\u903b\u8f91&#xff1a;<\/p>\n<p>&#x1f440;\u542f\u52a8HTTP\u670d\u52a1\u5668\u5e76\u76d1\u542c\u2192\u542f\u52a8express\u670d\u52a1\u5668\u3010\u5176\u4e2dapp.ues()\u52a0\u8f7d\u8def\u7531\u5904\u7406\u5668\u3011\u2192\u8def\u7531\u53ef\u4ee5\u7531\u81ea\u5df1\u914d\u7f6e\u8bbe\u5b9a<\/p>\n<p>\u90a3\u4e48\u6211\u73b0\u5728\u670d\u52a1\u5668\u542f\u52a8\u4e86&#xff0c;\u6211\u524d\u7aef&#xff08;\u5ba2\u6237\u7aef&#xff09;\u53d1\u6765\u7684\u6d88\u606f\u5df2\u7ecf\u53ef\u4ee5\u53d1\u9001\u5230\u6211\u7684\u670d\u52a1\u5668\u8fdb\u884c\u89e3\u6790&#xff0c;\u4f5c\u4e3a\u4e00\u540d\u5f00\u53d1\u8005\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b\u8fd9\u4e9b\u5177\u4f53\u7684\u5b9e\u73b0\u539f\u7406\u548c\u5982\u4f55\u8c03\u7528\u7684\u8fc7\u7a0b&#xff08;\u5982\u770b\u4e86\u8fd9\u7bc7\u6587\u7ae0\u53ef\u80fd\u5bf9\u4f60\u4fee\u6539\u7aef\u53e3\u7b49\u4e5f\u6709\u5e2e\u52a9&#xff09;&#xff0c;\u4f46\u662f\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u53ef\u4ee5\u4e4b\u95f4\u5728index\u79cd\u7f16\u5199\u8def\u7531\u5904\u7406\u7684\u903b\u8f91\u5373\u53ef\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"368\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418205726-6802bcb697168.png\" width=\"312\" \/><\/p>\n<p>\u5728\u4f60\u7684index.js\u79cd\u7f16\u5199\u4f60\u7684\u540e\u7aef\u4ee3\u7801\u5c31\u597d\u4e86&#xff0c;\u5982\u679c\u4e0d\u4f1a\u53ef\u4ee5\u770b\u770b\u6211\u5f15\u7528\u7684\u90a3\u7bc7\u6587\u7ae0&#xff0c;\u91cc\u9762\u7684\u6b65\u9aa4\u5f88\u8be6\u7ec6<\/p>\n<p>\n \u521b\u5efanodejs\u7684\u670d\u52a1\u5668\u8fd9\u4e2a\u90fd\u6ca1\u5565\u5dee\u522b&#xff0c;\u90fd\u662f\u5728\u6587\u4ef6\u4e2d\u8fdb\u884c\u64cd\u4f5c\u5373\u53ef<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u524d\u7aef\uff08\u5ba2\u6237\u7aef\uff09\u548c\u540e\u7aef\uff08\u670d\u52a1\u7aef\uff09\u901a\u8fc7nodejs\u662f\u5177\u4f53\u5982\u4f55\u8fdb\u884c\u4ea4\u4e92_node express \u542f\u52a8<\/p>\n","protected":false},"author":2,"featured_media":21686,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[709,186,1667,100],"topic":[],"class_list":["post-21688","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-express","tag-node-js","tag-nodejs","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09 - \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\/21688.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u524d\u7aef\uff08\u5ba2\u6237\u7aef\uff09\u548c\u540e\u7aef\uff08\u670d\u52a1\u7aef\uff09\u901a\u8fc7nodejs\u662f\u5177\u4f53\u5982\u4f55\u8fdb\u884c\u4ea4\u4e92_node express \u542f\u52a8\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/21688.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-18T20:57:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418205726-6802bcb676574.png\" \/>\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\/21688.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/21688.html\",\"name\":\"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T20:57:27+00:00\",\"dateModified\":\"2025-04-18T20:57:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/21688.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/21688.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/21688.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09\"}]},{\"@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":"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09 - \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\/21688.html","og_locale":"zh_CN","og_type":"article","og_title":"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u524d\u7aef\uff08\u5ba2\u6237\u7aef\uff09\u548c\u540e\u7aef\uff08\u670d\u52a1\u7aef\uff09\u901a\u8fc7nodejs\u662f\u5177\u4f53\u5982\u4f55\u8fdb\u884c\u4ea4\u4e92_node express \u542f\u52a8","og_url":"https:\/\/www.wsisp.com\/helps\/21688.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T20:57:27+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418205726-6802bcb676574.png"}],"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\/21688.html","url":"https:\/\/www.wsisp.com\/helps\/21688.html","name":"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T20:57:27+00:00","dateModified":"2025-04-18T20:57:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/21688.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/21688.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/21688.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"node.js\u542f\u52a8Express\/Http \u670d\u52a1\u5668\u8fde\u63a5\u672c\u5730\u6570\u636e\u5e93\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\uff08\u5b9e\u64cd\uff09"}]},{"@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\/21688","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=21688"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/21688\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/21686"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=21688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=21688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=21688"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=21688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}