Estoy ejecutando este código pero me da este error. const hashPassword = await bcrypt.hash(req.body.password, 10) SyntaxError: await solo es válido en funciones asíncronas y cuerpos de módulos de nivel superior
app.post('/register', (req, res) => { //register/signup try{ const hashedPassword = await bcrypt.hash(req.body.password, 10) users.push({ id: Date.now().toString(), name: req.body.name, email:req.body,email, password: hashedPassword }) res,redirect('/login') }catch{ res.redirect('/register') } console.log(users) })`enter code here`Simplemente marque la función de devolución de llamada pasada al método app.post como async .
app.post('/register', async (req, res) => { try{ const hashedPassword = await bcrypt.hash(req.body.password, 10) users.push({ id: Date.now().toString(), name: req.body.name, email:req.body,email, password: hashedPassword }) res,redirect('/login') }catch{ res.redirect('/register') } console.log(users) })