【发布时间】:2021-05-23 18:39:18
【问题描述】:
我正在为我的应用程序使用节点打字稿。我使用邮递员提出了基本的发布请求。我控制台记录请求正文。我得到了数据,但在邮递员中不断显示发送请求和image。我在我的代码中没有看到任何错误。我不知道发布请求中有什么问题。 ps:This is my first time I am using node-typescript express server.
这基本上是我所有的快递代码
import express, { Application, Response, Request } from 'express';
import cors from 'cors';
import morgan from 'morgan';
import helmet from 'helmet';
const app: Application = express();
const port = 8000;
app.use(cors());
app.use(morgan("common"));
app.use(helmet());
app.use(express.json());
app.post('/api', (req: Request, res: Response) => {
console.log(req.body.Item); // I get the data
})
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`)
})
这是我的命令脚本
"scripts": {
"build": "tsc -p .",
"start": "ts-node server.ts",
"server": "ts-node server.ts"
},
【问题讨论】:
标签: node.js typescript express post postman