You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Express中Get/Post/Put/Delete路径参数新手疑问求助

Understanding Express Route Paths (They’re Not Folders!)

Hey there! As someone who’s been working with Express for a while, I totally get why this might confuse you at first—let’s clear this up step by step.

First off, the route path in Express has nothing to do with physical folders on your server. It’s purely a logical identifier that uses URL structure to match incoming HTTP requests to the right code.

Let’s break down your example code:

app.post("/quotes", (req, res) => {
  quotesCollection.insertOne(req.body)
    .then((result) => res.redirect("/"))
    .catch((error) => console.error(error));
});

Here’s what /quotes actually means:

  • When a client (like a frontend form, Postman, or any other HTTP client) sends a POST request to a URL like http://your-server-domain/quotes, Express checks all its registered routes and matches this request to the function you’ve defined here.
  • It doesn’t look for a folder named quotes on your server—this path is just a way to label which requests should trigger this specific code (in your case, inserting a new quote into a database and redirecting the user).

To tie this back to the official docs you mentioned: /quotes is a simple string path, one of the allowed types (along with path patterns, regex, or arrays of these). Express uses these paths to route traffic to the right handlers, regardless of your server’s file system structure.

A quick side note: The only time Express paths map to folders is when you use express.static to serve static files (like HTML, CSS, or images). But that’s a separate feature—your app.post("/quotes") route is a custom business logic route, not tied to any physical files.

内容的提问来源于stack exchange,提问作者user12421682

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:28:59