请求在express.js 中挂起

Jos*_*ton 3 node.js express

我创建了一个全新的 Express API 应用程序,由于某种原因,当我运行它时(命令是node src/index.js),两个请求都挂起并且永远没有响应。我已经能够将其app.use(express.json)作为罪魁祸首钉在网上。当它被注释掉时,请求似乎有效,但随后我无法访问请求正文。

const app = express();

app.use(express.json);

app.post("/api/user/register", (req, res) => {
    res.send("Ok");
});

app.listen(3000, () => {
    console.log("API is up and running!");
});
Run Code Online (Sandbox Code Playgroud)

我的package.json文件的内容如下:

  "name": "api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node src/index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  }
}
Run Code Online (Sandbox Code Playgroud)

我当前正在运行节点版本 13.2.0。关于下一步尝试什么有什么建议吗?(我是节点新手,因此我们将不胜感激)

Jos*_*ton 9

应该app.use(express.json());不是app.use(express.json);