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

205
Views
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 answers
Answer question

0

To send multiple values:-

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

about 4 years ago · Juan Pablo Isaza Report

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 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!