javascript - 没有正文解析器的 Express 输入 JSON 在哪里?

标签 javascript node.js express node-modules body-parser

我知道 body-parser 及其作用。我很想知道在使用 express 时请求的数据在哪里。在 body-parser 解析输入之前存在哪种格式。

// parse urlencoded types to JSON
app.use(bodyParser.urlencoded({
    extended: true
}));

// parse various different custom JSON types as JSON
app.use(bodyParser.json({ type: 'application/*+json' }));

// parse some custom thing into a Buffer
app.use(bodyParser.raw({ type: 'application/vnd.custom-type' }));

// parse an HTML body into a string
app.use(bodyParser.text({ type: 'text/html' }));

如果不使用这些,数据将在哪里?它将以哪种格式提供?

最佳答案

Node documentation 中对此进行了相当详尽的介绍。 .

The request object that's passed in to a handler implements the ReadableStream interface. This stream can be listened to or piped elsewhere just like any other stream. We can grab the data right out of the stream by listening to the stream's 'data' and 'end' events.

Express 实际上是在对 Node.js HTTP 服务器功能应用扩展,包括扩展 native Request 和 Response 对象。因此,您同样可以像处理 native request object as well 一样处理 Express 请求。

关于javascript - 没有正文解析器的 Express 输入 JSON 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52122643/

相关文章:

javascript - 如何使用自动启动在系统启动时启动应用程序?

javascript - nodejs 中的 for 循环不适用于 redis hexists

node.js - 如何将 AWS Cognito 与自定义 NodeJS 服务器结合使用?

mysql - Node、Sequelize、Mysql - 如何为模型定义排序规则和字符集?

angular - 部署/运行: local Express web-server and local client-side angular app that sends ajax requests to this local web-server

javascript - MutationObserver 仅在第一次更改时触发

javascript - 使用 xPath(javascript, jquery) 从 url 链接解析 html 页面

sql - 获取刚刚添加的行的最佳方式。 Heroku + Node + Postgres

javascript - Div 在 React 转换之前就已经填满了它的位置

javascript - 在 jQuery 中查找父元素的数量