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 7823759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:22:04+00:00 2026-06-02T08:22:04+00:00

So say I’ve got a function: function grabOldestJob() { var client = mysql.createClient({ user:

  • 0

So say I’ve got a function:

function grabOldestJob() {
  var client = mysql.createClient({
    user: dbConfig['USER'],
    password: dbConfig['PASS'],
  });

  client.query('USE '+dbConfig['DATABASE']);

  client.query('SELECT url FROM '+dbConfig['JOB_TABLE']+' ORDER BY added ASC LIMIT 1 ',
    function selectCb(err, results, fields, passed) {
      if (err) {
        throw err;
      }
      client.end();
      fetchFeed(results[0]['url']);
    }
  );
}

What I need is the results[0][‘url’] buried in the inline function, so either I’d like to get that variable out of that function so I can use it to return the grabOldestJob function or pass another function into the inline function so I can use results[0][‘url’] as a parameter.

I’m very new to the concepts of node.js and would like to make my code as ‘proper’ as possible. This function is the first in a process, it pulls a url out of a database, passes that to get fetched from the remote server, the xml feed gets parsed and certain bits get stored in a database. I’m hoping using the ability of node to ‘run lots of things at once’ I’ll be able to fetch->parse->save many feeds at the same time. Any best practice tips for this would also be greatly appreciated.

  • 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-02T08:22:07+00:00Added an answer on June 2, 2026 at 8:22 am

    Use callback functions for this.

    Like the client.query(query,callback) function does. You pass in the data and a callback function that gets called if the processing completed. Do the same with your fetchFeed(url,callback) function.

    ...
    client.end();
    fetchFeed(results[0]['url'],function(result){
        // here 'result' contains the fetched feed and can be stored into the database
    });
    ...
    

    function fetchFeed(url,cb){
        // download feed here and call cb(downloaded_data) when finished, passing the downloaded data to the cb() function
    }
    

    Have a look at: Understanding the node.js event loop

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

Sidebar

Related Questions

Say I have a LINQ-to-XML query that generates an anonymous type like this: var
Say I've got this array: MyArray(0)=aaa MyArray(1)=bbb MyArray(2)=aaa Is there a .net function which
Say I have two types of objects, Apples and Chainsaws . A user is
Say I have the following template function: template <class T> void apply(const vector<complex<T> >&
Say in my js file I want to have var NO = 0; var
Say a development team includes (or makes use of) graphic artists who create all
Say I have a public method1 calling a private method2 , I use a
Say using following function: getUnique(){ MyObject obj = getValueFromDb(); obj.modifyIt(); obj.commit(); } When simultaneous
Say I have a function pointer in C- library int (*fptr)(void); And I have
say if I wanted to give every user that registered on my site a

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.