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 6183397

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:21:29+00:00 2026-05-24T01:21:29+00:00

I’m playing with a Node.JS app for the first time, and so far I

  • 0

I’m playing with a Node.JS app for the first time, and so far I love it, but I’m having a problem…

I have written a wrapper function on the client.query function that simply allows me to pass a parameter and it gets the query from an array of allowed queries…

    var runProcedure = function(proc, vars){
    var params;
    if(typeof vars != 'undefined'){
      params.concat(eval('(' + vars + ')'));
    }

    this._client.query(queries[proc], params, function(err, results, fields){
        if(err) { throw err; }
        if(results){
            return(results);
        }else{
            return "No data found.";
        }
    });
}

The function works correctly and if I console.log results, the data I want is there.. however, it’s not getting returned to where I called it…

    var data = runProcedure(procedureName, parameters);
    console.log(data); // undefined

While troubleshooting, it seems that the query function is run asynchronously…. but this causes me a big problem. The runProcedure function is being called from within an http request handler.. so I need to be able to access the response variable. I guess I could pass it all the way down as a parameter… but that seems clumsy. What is the best code pattern to handle this? Should I set the response as a global var? can I run the mysql synchronously?

Cheers,

whiteatom

  • 0 0 Answers
  • 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-05-24T01:21:31+00:00Added an answer on May 24, 2026 at 1:21 am

    just pass your data to callback instead of returning with return

    var runProcedure = function(proc, vars, callback) {
    
        var params;
        if(typeof vars != 'undefined'){
          params.concat(eval('(' + vars + ')'));
        }
    
        this._client.query(queries[proc], params, function(err, results, fields){
            if(err) { throw err; }
            if(results){
               callback(results);
            }else{
               callback('No data found.');
            }
        });
    

    }

    Now in http request handler:

    // ...
    function httpRequestHandler(req, resp)
    {
        //...
        runProcedure(proc, vars, function(dbResp) {
            if (dbResp === 'No data found.')
            {
                // handle error
            } else {
                // do something with result
            }     
        })
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.