Node.js Req.body已填充,但Req.body.user和Req.body.pass不是';T

Node.js Req.body已填充,但Req.body.user和Req.body.pass不是';T,node.js,api,express,post,body-parser,Node.js,Api,Express,Post,Body Parser,我正在从头开始做Auth。我在对api运行post请求时遇到问题。如果我使用postman并填充表单数据部分和post,则req.body.user和req.body.pass中没有任何内容。但是,当然,req.body被填充,我可以看到我发送的表单数据。这是我的密码: const express = require("express"), app = express(), shajs = require("sha.js"), bodyParser = require("body-p

我正在从头开始做Auth。我在对api运行post请求时遇到问题。如果我使用postman并填充表单数据部分和post,则req.body.user和req.body.pass中没有任何内容。但是,当然,req.body被填充,我可以看到我发送的表单数据。这是我的密码:

const express = require("express"),
  app = express(),
  shajs = require("sha.js"),
  bodyParser = require("body-parser"),
  mongoose = require("mongoose"),
  Schema = mongoose.Schema;

mongoose.connect('mongodb://localhost:27017/auth', {useNewUrlParser: true});

app.use(bodyParser.urlencoded({ extended: true }));

let userSchema = new Schema({
  username: String,
  password: String
});

let user = mongoose.model("user",userSchema);

app.post("/user/register",(req,res)=>{
  console.log(req.body);
  let hashedPass = shajs("sha256").update(req.body.pass).digest("hex");
  let newUser = new user({
    username: req.body.user,
    password: hashedPass
  });
});

app.listen(3000,(err,suc)=>{
  if(err){
    console.log(err);
  } else {
    console.log("Yay! The app is up on localhost:3000.");
  }
});
以下是我的req.body的外观:

 { '------WebKitFormBoundaryBZtUrMPzNKlsGLwj\r\nContent-Disposition: form-data; name':
   '"user"\r\n\r\nBlakskyben\r\n------WebKitFormBoundaryBZtUrMPzNKlsGLwj\r\nContent-Disposition: form-data; name="pass"\r\n\r\nBENNNN\r\n------WebKitFormBoundaryBZtUrMPzNKlsGLwj--\r\n' }

谢谢你,本

bodyParser
不处理
表单数据
。您将需要为此使用

否则请使用
application/x-www-form-urlencoded
,因为您已经:

app.use(bodyParser.urlencoded({ extended: true }));
在Postman中,不要使用
表单数据
收音机,而是使用
x-www-form-urlencoded
收音机