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

  • Home
  • SEARCH
  • 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 8932493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:19:37+00:00 2026-06-15T09:19:37+00:00

NOTE: This question has very little jQuery, Drupal, or node.js it’s more of a

  • 0

NOTE: This question has very little jQuery, Drupal, or node.js it’s more of a generic question on “how frameworks achieve X, where X is something any of the frameworks I mentioned also provides.

I saw an example node.js code that looks like this:

var http = require('http');
var server = http.createServer();
server.listen(8000);
server.on('request', function(req, res) {
    //do something with req and res here
});

There is no obvious place where req and res are coming from. In fact, what does 'request' mean? Where is it supplied from?

I have noticed similar things in jQuery .get() and .post() functions, and looking at the source did not help as much as I would like. I’ve even seen this being done in Drupal; a function is defined in the theme layer or as a module_hook with specific naming conventions by me, but arguments appear outta nowhere and there is a predictable structure of data (specified in the manual) inside those magic variables.

So what is this technique called, and how does it work. I’ve heard tell of Dependency Injection… is this it? If it is, could you explain in n00b terms how it is accomplished?

This is particularly confusing because I coded in procedural from the start, and we always know where a variable is coming from and how a function is being called…

  • 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-15T09:19:38+00:00Added an answer on June 15, 2026 at 9:19 am

    In fact, what does request mean? Where is it supplied from?

    Whenever you want to access a web site, you’re using a special protocol, the hypertext transfer protocol (HTTP). This protocol mainly uses two things:

    1. a question from the client like “what is / on your server?” (the request)
    2. an answer from the server like “it’s a text/html, the length is 2000 bytes, and here is the document” (the response).

    This request-response model is used directly in node.js, as the server you’re using is a HTTP server.

    […] could you explain in n00b terms how it is accomplished?

    Do you know what a main-loop or event-loop is? Almost every GUI application has one. It’s basically a loop like this:

    while(waitForNewEvent(&event)){
        handleMsg(&event);
    }
    

    This event can be anything, from keyboard input to another software trying to bring your window to front. It can also be something like “are you ready for standby?”.

    node.js uses such a event-loop in it’s server implementation. server.on('request', callback) basically tells node.js that you want callback to be used whenever a request is coming:

    while(waitForNewEvent(&event)){
        if(event == "request"){
            callback(request,&response);
            responseToClient(response);
        }
    }
    

    Intern example

    Or even simplier: think of a intern, who’s just running around in circles in a building. He’s the event-loop. Now in your server room someone tells him that every request should be brought to them. He writes this down and continues on his never-ending tour.

    Then someone stands in front of the building and wants to check his bank-account. He simply throws a request into a post box and the intern rushes to the server room and tells the technicians that the specific site has been requested and gives them the necessary information. However, he needs to wait on their response, since their response isn’t on his list.

    The technicians check the request and find out that the user isn’t qualified for the given request(*). They prepare an error message and give it to the intern. He now returns to the front of the building, gives the error message to the first client and is ready for other messages.

    (*): At this point they might need to check something in a database, which might take some time. They could tell the intern to come back later and call him if they’re ready. In this case the intern could continue his way until the technicians are ready.

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

Sidebar

Related Questions

(Note: My question has very similar concerns as the person who asked this question
Note: this question has nothing to do with Knockout.js, but it's about the selectedOptions
Note: This question has broadened in scope from previous revisions. I have tried to
I think this question is very usual. Many results on Stackoverflow has said about
Note : Before asking this question I did an exhaustive search, and found little
(Note, this question has been marked answered in Debugging Sharepoint timer jobs but I'm
This question has been asked in Microsoft interview. Very much curious to know why
Please note: This question is very similar to this one I found on stackoverflow.
This should be a fairly simple question but I know very little about SQL.
note: this is a direct follow up to this previous question I have very

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.