Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:25:48+00:00 2026-06-04T22:25:48+00:00

app.post(‘/login’, function (req, res) { var login = req.body.login; var pass = req.body.pass; var

  • 0
app.post('/login', function (req, res) {

    var login = req.body.login;
    var pass = req.body.pass;

    var ret = CheckUserValid(login, pass);

  res.send(ret);
})

function CheckUserValid(login, pass,callback) {
    var sql = "SELECT * FROM `user` WHERE login = ? AND pass= ?";
    client.query(sql, [login, pass], function selectResutl(err, results, fields) {
         console.log(results);
        if (!err) return true;
        else
            throw err;
    });
}

first Function is about request and second is about making call to mysql. because it’s async so it’s not worked.
Can someone let me know how I can make it work synchronously like in C#.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:25:49+00:00Added an answer on June 4, 2026 at 10:25 pm

    The signature of your CheckUserValid method already implies a callback.
    You can use that to call something when your db-request is done, like this:

    app.post('/login', function (req, res) {
      var login = req.body.login;
      var pass  = req.body.pass;
    
      // use a closure here for the callback of checkUserValid
      checkUserValid(login, pass, function(err, isValid) {
        // send the response when checkUserValid is done
        res.send(isValid)
      });
    })
    
    function checkUserValid(login, pass, callback) {
      var sql = "SELECT * FROM `user` WHERE login = ? AND pass= ?";
      client.query(sql, [login, pass], function(err, results, fields) {
        console.log(results);
        if (!err) {
          // there is no error, pass null for the error
          // and true for the result
          callback(null, true);
        } else {
          // an error occurred in the db-query
          // pass it to the callback
          callback(err)
        }
      });
    }
    

    By convention you should pass the err as first argument, but in the end that’s up to you.
    However you can pass the original error up to your initial function and handle it there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an express app and a POST route: app.post('/test', function(req, res){ //res.send(req.body.title +
How can I test a function like this? app.post '/incoming', (req,res) -> console.log Hello,
Having a XML response like: app.post '/incoming', (req,res) -> console.log Hello, incoming call! message
Hello I am working with an ajax post function, where I send data and
I am trying to do the following: from client var req = jQuery.post( http://www.example.com:3000+/dologin,
I'm trying to get an Android app to post highscores to Facebook, similar to
We are about to post an app that use UDID. We plan to remove
Background: I am making a facebook app where users post messages like in a
I am trying to integrate Facebook to my Android app for social post. I
Every time I try to post to twitter in my rails app, the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.