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

109
Views
Variable indefinida como resultado de la llamada a la API en JS

Estoy tratando de obtener la parte dataValues de un objeto JSON que devuelve esta función a la que llama una llamada API:

 exports.findOne = (req, res) => { const id = req.params.id; Users.findByPk(id) .then(data => { if(data){ console.log("data: ", data); res.send(data); } else { res.status(404).send({ message: "Cannot find user with id=${id}" }); } }) .catch(err => { res.status(500).send({ message: err.message || "Error retrieving Tutorial with id=" + id }); }); };

Esta es la salida para cuando imprimo datos:

 findOne: Login { dataValues: { ID: 20, username: 'phil_swift', email: 'philswift@flextape.com', password: '<ENCRYPTED>', account_type: 1, token: null, token_expiration: null, require_password_at_login: false }, _previousDataValues: { ID: 20, username: 'phil_swift', email: 'philswift@flextape.com', password: '<ENCRYPTED>', account_type: 1, token: null, token_expiration: null, require_password_at_login: false }, uniqno: 1, _changed: Set(0) {}, _options: { isNewRecord: false, _schema: null, _schemaDelimiter: '', raw: true, attributes: [ 'ID', 'username', 'email', 'password', 'account_type', 'token', 'token_expiration', 'require_password_at_login' ] }, isNewRecord: false }

En el front-end, cuando realizo esta solicitud GET, devuelve indefinido.

 const { dataValues } = await httpCommon.get("/" + this.state.user.userID); console.log("dataValues: ", dataValues);

¿Cómo es que sucede esto y cómo puedo solucionarlo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Le doy crédito a @codemonkey por darme esta sugerencia que funcionó. res.send(data) con res.json(data) .

about 4 years ago · Juan Pablo Isaza 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!