小编Ант*_*сун的帖子

正文解析器不适用于打字稿,当我发送请求时,我在 request.body 中收到未定义的信息

这是我使用 typescript 3.7.4 的 Express 应用程序的以下代码:

import bodyParser from "body-parser";
import config from "config";
import cookieParser from "cookie-parser";
import express from "express";
import mongoose from "mongoose";
import path from "path";

export default class App {

    public app: express.Application;

    constructor() {
        this.app = express();
        this.initializeMiddlewares();
    }

    public listen(port: any) {
        this.app.listen(port, () => {
            console.log(`App listening on the port ${port}`);
        });
    }

    public initializeControllers(controllers: any) {
        controllers.forEach((controller: any) => {
            this.app
                .use(bodyParser.json())
                .use(bodyParser.urlencoded())
                .use("/", controller.router);
        });
    }

}`
Run Code Online (Sandbox Code Playgroud)

请帮我解决这部分代码。我不明白,当我发送帖子请求时,为什么我在 request.body 中未定义。

javascript node.js express typescript body-parser

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

body-parser ×1

express ×1

javascript ×1

node.js ×1

typescript ×1