[英]Why am I getting a null message?
I keep getting a null after testing my register page.在测试我的注册页面后,我不断收到 null。 Null
Null
This is the code这是代码
app.post("/register", function (req, res) {
const newUser = new User({
email: req.body.email,
password: req.body.password
});
newUser.save(function (err) {
if (!err) {
console.log(err);
} else {
res.render("secrets");
}
});
}); });
I think thats because you have no errors.我认为那是因为你没有错误。 You're checking for
if (!err)
.您正在检查
if (!err)
。 This statement will print everything inside if
block if there are no errors, that's why you're getting null.如果没有错误,此语句将打印
if
块中的所有内容,这就是您得到 null 的原因。
I think you should change it to if (err)
to avoid entering the if
block, if there are no errors我认为您应该将其更改为
if (err)
以避免进入if
块,如果没有错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.