Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
send response to client in node js express is not working

I am trying to send back response to the client but it seems it is not working, I don't know why, because after all I am not getting any errors.

here is my code:

exports.login = function (req, res, next, con) {
    if (!req || !res || !next || !con) return res.status(500).set({ msg: 'null variables' });

    var email = req.body.email, password = req.body.password;
    if (!email || !password) return res.status(500).set({ msg: 'null values' });
    var format = /^[!#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/;

    if (!email.match(format)) {
        query1 = "SELECT `id`, `password` FROM `ceo`.`users` WHERE `email`= '" + email + "'"
        // check users exists with this email
        con.query(query1, (err, result) => {
            const bcrypt = require('bcrypt');
            var jwtGenerator = require('./../../classes/JWT/JWTgenerator')

            if (err) return res.status(500).set({ msg: 'error checking' })
            if (result.length === 0) return res.status(500).set({ msg: 'wrong email' })
            // check password
            bcrypt.compare(password, result[0].password, function (err) {
                if (err) return res.status(500).set({ msg: 'wrong password' })

                // update refreh token in database
                const rtoken = jwtGenerator.generateRefreshToken({ id: result[0].id });
                var queryUpdate = "UPDATE `token` SET `_token` = '"+rtoken+"' WHERE `token`.`id` = '"+result[0].id+"';"
                con.query(queryUpdate, (err) => {
                    if (err) return res.status(500).set({ msg: 'error in update' })
                    res.status(200).set({
                        msg: {
                            accessToken: jwtGenerator.generateAccessToken({ id: result[0].id }),
                            refreshToken: rtoken
                        }
                    })
                });
            });

        });
    } else {
        return res.status(500).set({ msg: 'special chars' })
    }

}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

To send multiple values:-

res.status(200).json({ msg: 'success',data:response });

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think you have to use .send instead of set !!

Like this :

res.status(500).send({ msg: 'null values' });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda