我正在尝试使用node和express创建一个简单的注册路由。由于某种原因,req.body.name被突出显示为未解析的变量名称。
在postman中运行时,它会发出验证错误并说“#34; Path {PATH}
是必需的。"
我的javascript代码:
router.post('/', function(req, res) {
var participant = new Participant({
name:req.body.name, // this is the place where unresolved variable is coming
regno:req.body.regno,
gender : req.body.gender,
email : req.body.email,
mobile : req.body.mobile,
room : req.body.room,
adgid : req.body.adgid
});
participant.save(function(err,docs) {
if(docs) {
res.json({
"message":docs
})
}
else{
res.json({
code: '1',
message: err
})
}
});
我的模特档案:
var mongoose = require('mongoose');
var participantSchema = mongoose.Schema({
name:{ type: String , required :true},
regno:{ type:String, required :true },
gender:{ type:String, required :true },
mobile:{ type: Number ,required :true },
email:{ type:String,required :true },
room:{ type:String ,required :true },
adgid : {type:String , required : true}
});
var Participant = mongoose.model('Participant', participantSchema);
module.exports= {Participant : Participant};