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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:18:22+00:00 2026-05-30T12:18:22+00:00

In http://nodejs.org/docs/v0.4.7/api/http.html#http.request There is an example that fetches some web content, but how does

  • 0

In http://nodejs.org/docs/v0.4.7/api/http.html#http.request

There is an example that fetches some web content, but how does it save the content to a global variable? It only accesses stuff the function.

  • 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-30T12:18:23+00:00Added an answer on May 30, 2026 at 12:18 pm

    If look closely at the example, that HTTP request is used to POST data to a location. In order to GET web content, you should use the method GET.

    var options = {
        host: 'www.google.com',
        port: 80,
        method: 'GET'
    };
    

    The HTTP response is available in the on-event function inside the callback-function which is provided as the parameter for the constructor.

    var req = http.request(options, function(res)
    {
        res.setEncoding('utf8');
        var content;
        res.on('data', function (chunk)
        {
          // chunk contains data read from the stream
          // - save it to content
          content += chunk;
        });
    
        res.on('end', function()
        {
          // content is read, do what you want
          console.log( content );
        });
    });
    

    Now that we have implemented the event handlers, call request end to send the request.

    req.end();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading the docs at http://nodejs.org/docs/v0.4.0/api/http.html#http.request , but for some reason, I can't seem
I can't find anything in the docs on exactly how to do this. http://nodejs.org/api.html#request-method-149
Maybe it's just the fact that I've been using http://nodejs.org/ lately, but the lack
I'm doing a simple UDP send using Node's inbuilt datagram UDP socket : http://nodejs.org/docs/v0.3.1/api/dgram.html
http://developer.yahoo.com/javascript/howto-proxy.html Are there disadvantages to this technique? The advantage is obvious, that you can
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
We know there is Union and find for disjoint sets. http://en.wikipedia.org/wiki/Union_find But how to
The following article http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXPXSLT3.html says that XPATH considers the following to be nodes: Root
I downloaded the nodeJs package installer for OSX http://nodejs.org/dist/v0.6.5/node-v0.6.5.pkg But when I run node
http://en.wikipedia.org/wiki/Diamond_problem I know what it means, but what steps can I take to avoid

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.