Node.js ReferenceError:未定义nome
我试图让函数检索回调。第一个错误是回调参数不是一个函数,然后我试图修正我的语法,即没有定义参数 控制器:第10行错误:Node.js ReferenceError:未定义nome,node.js,express,Node.js,Express,我试图让函数检索回调。第一个错误是回调参数不是一个函数,然后我试图修正我的语法,即没有定义参数 控制器:第10行错误: //Tried to declare like "function registraU(nome, ... ()) const registraUsuario = (nome, email, password, (e, usuarioCriado) => { UsuarioModel.findOne({ email: email }, (e, ma
//Tried to declare like "function registraU(nome, ... ())
const registraUsuario = (nome, email, password, (e, usuarioCriado) => {
UsuarioModel.findOne({ email: email }, (e, match) => {
if (e) { return callback(e); }
if (match !== null) {
return callback(null, null);
} else {
var hash = bcrypt.hashSync(password, 10);
password = hash;
novoUsuario = {
nome: nome,
email: email,
password: password
}
var temp = new UsuarioModel(novoUsuario);
temp.save(function(e, usuarioCriado){
if(e){console.log(e)};
return callback(null, usuarioCriado);
});
}
});
});
这是调用它的代码:
passport.use('local-registro', new LocalStrategy({
nomeField: 'nome',
emailField: 'email',
passwordField: 'password',
passReqToCallback : true
},
(req, nome, email, password, done) => {
UsuarioController.registraUsuario(nome, email, password, (e, callback) => {
if(e) {return done(e); }
if(!novoUsuario){
return done(null, false, req.flash({"erroRegistro": "Email já cadastrado"}));
} else {
return done(null, novoUsuario);
}
});
}
));
您将声明为一种es6 arrow函数,但忘记添加函数体
const registraUsuario = (nome, email, password, (e, usuarioCriado) => {...});
但你们身体的其他部分在哪里呢
const registraUsuario = (nome, email, password, (e, usuarioCriado) => {...}) => {
// your function body
}
这就是你的代码被破坏的原因。。。它不被解释为函数声明