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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:59:21+00:00 2026-05-23T14:59:21+00:00

I’m having some trouble with Node.js, and I think the problem might be that

  • 0

I’m having some trouble with Node.js, and I think the problem might be that I am misunderstanding Node.js’s approach to concurrency. Here is a stripped down example of the server I have written. The idea is that the server will be used for automated testing: it keeps a list of expected “configurations”, and compares them to “configurations” that are sent by the client.


//expectedConfigurations gets initialized up here

var server = http.createServer(function(request, response) {
    switch (url.pathname) {
        case "/check-configuration":
            jsonData = "";
            request.on("data", function(data) {
                return jsonData += data;
            });

            request.on("end", function() {
                var configuration, errMsg, expectedConfiguration;

                console.log("finished reading json data", jsonData);
                expectedConfiguration = expectedConfigurations.shift();
                console.log("Expected configuration", expectedConfiguration);
                configuration = new Set(JSON.parse(jsonData));
                if (expectedConfiguration.equals(configuration)) {
                    response.writeHead(200, {"Content-Type": "text/plain"});
                    response.write("Matched expected configuration.");
                    return response.end();
                } else {
                    response.writeHead(500, {
                        "Content-Type": "text/plain"
                        });
                    errMsg = "Did not match expected configuration. Received: " + (JSON.stringify(configuration)) + ". Expected:" + (JSON.stringify(expectedConfiguration)) + ".";
                    response.write(errMsg);
                    response.end();
                    console.error(errMsg);
                    results.testsFailed.push(currentTest);
                    return transitionToBeforeSendingTestState();
                }

            })
    }
})

My understanding is that Node.js is single-threaded, so while it can spawn multiple tasks which can be handled asynchronously, only one thread of execution at a time will enter the JavaScript code running under Node.js. Unfortunately, the debugging output I am receiving from my server seems to defy this assumption:


received request for /check-configuration
finished reading json data [ "a" ]
Expected configuration [ "a" ]
received request for /check-configuration
Did not match expected configuration. Received: [ "a" ]. Expected: [ "c" ].

I read this as the following:

  1. the server receives a request. It starts reading request data asynchronously.
  2. the server finishes reading request data, mutates expectedConfigurations by shifting it, and assigns the results to expectedConfiguration [ 'a' ]
  3. the thread then gets interrupted by a new request to the server! this is where my expectations of single-threaded execution of JavaScript content under Node.js seem to break down.
  4. finally, the original thread of execution associated with the first request resumes. The expected configuration is compared to the received actual configuration, but now, instead of having the value [ 'a' ], as it did in step 2., it has the value ["c"].

It seems I must be interpreting this incorrectly, because it defies my understanding of Node.js’s single-threaded execution model, but right now I’m unable to see how else this can be interpreted. I’d appreciate any guidance anyone can offer on this.

  • 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-05-23T14:59:21+00:00Added an answer on May 23, 2026 at 2:59 pm

    try to repeat same test using console.error instead of console.log everywhere.
    As far as I know, console.log is non-blocking (data is buffered at the time of call and written to stdout at some point later) and console.error is blocking.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

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.