Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
(nodo: 19652) UnhandledPromiseRejectionWarning: ReferenceError: No se puede acceder a 'contraseña' antes de la inicialización

No sé cómo debo resolver este error ... también, recibí una advertencia que dice: Advertencia: Accediendo a la propiedad inexistente 'MongoError' de las exportaciones de módulos dentro de la dependencia circular (Use node --trace-warnings ... para mostrar dónde se creó la advertencia)

 const express =require('express'); const mongoose = require('mongoose'); const path = require('path'); const User = require('./model/user.js') const bcrypt = require('bcryptjs'); mongoose.connect('mongodb://localhost:27017/login-app-db',{ useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true }) const app = express(); app.use('/', express.static(path.join(__dirname, 'static'))); app.use(express.json()); app.post('/api/register', async(req, res)=>{ console.log(req.body); const {username, password: plainTextPassword}= req.body; const password = await bcrypt.hash(password, 10); try { const response = await User.create({ username, password }) console.log('User created successfully:', response) } catch (error) { console.log(error); return res.json({ status: 'Error'}); } console.log(await bcrypt.hash(password, 10)); res.json({status: 'ok'}) }) app.listen(9999, () => { console.log('Server Running at \'localhost:9999\''); })

mis dependencias del paquete:

 "bcryptjs": "^2.4.3", "express": "^4.17.1", "mongodb": "^3.6.3", "mongoose": "^5.11.15", "nodemon": "^2.0.7", "path": "^0.12.7" }

alguna pista??

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Asegúrese de analizar los datos desde su frente. Y edite su código y hágalo simple y menos detallado.

Consejos: Por fin usas estos:

  1. analizador de cuerpo
  2. CORS

Esto debería funcionar.

 app.post('/api/register', async(req, res)=>{ req.body.password = bcrypt.hashSync(req.body.password, 10) const response = new User(req.body) try { await response.save() return res.status(200).json({status : 'ok'}) } catch (error) { console.log(error); return res.json({ status: 'Error'}); } })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!