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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:54:07+00:00 2026-06-08T06:54:07+00:00

I can’t seem to grasp how to maintain async control flow with NodeJs. All

  • 0

I can’t seem to grasp how to maintain async control flow with NodeJs. All of the nesting makes the code very hard to read in my opinion. I’m a novice, so I’m probably missing the big picture.

What is wrong with simply coding something like this…

function first() {
    var object = {
        aProperty: 'stuff',
        anArray: ['html', 'html'];
    };
    second(object);
}

function second(object) {
    for (var i = 0; i < object.anArray.length; i++) {
        third(object.anArray[i]);
    };
}

function third(html) {
    // Parse html
}
first();
  • 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-08T06:54:08+00:00Added an answer on June 8, 2026 at 6:54 am

    The “big picture” is that any I/O is non-blocking and is performed asynchronously in your JavaScript; so if you do any database lookups, read data from a socket (e.g. in an HTTP server), read or write files to the disk, etc., you have to use asynchronous code. This is necessary as the event loop is a single thread, and if I/O wasn’t non-blocking, your program would pause while performing it.

    You can structure your code such that there is less nesting; for example:

    var fs = require('fs');
    var mysql = require('some_mysql_library');
    
    fs.readFile('/my/file.txt', 'utf8', processFile);
    
    function processFile(err, data) {
      mysql.query("INSERT INTO tbl SET txt = '" + data + "'", doneWithSql);
    }
    
    function doneWithSql(err, results) {
      if(err) {
        console.log("There was a problem with your query");
      } else {
        console.log("The query was successful.");
      }
    }
    

    There are also flow control libraries like async (my personal choice) to help avoid lots of nested callbacks.

    You may be interested in this screencast I created on the subject.

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

Sidebar

Related Questions

Can we close all known/unknown connections to database with the code? I'm using Access
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can i get the source code for a WAMP stack installer somewhere? Any help
Can a UIPickerView load a specific .nib / .xib file from code or UI
Can't get this working.. What am I missing here.. NodeJS, Mongoskin.. I cannot get
can any one tell me how can change this java code into objective c.is
Can anyone let me know how can we change the value of kendo combobox

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.