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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:15+00:00 2026-06-17T15:31:15+00:00

I’m building an application in node.js wich loads several pages an analyses the contents.

  • 0

I’m building an application in node.js wich loads several pages an analyses the contents.

Because node.js sends chunks I can analyse the chunks. If a chunk contains for example index,nofollow I want to close that connection and go on with the rest.

var host  = 'example.com',
    total = '',
    http  = require('http');

var req = http.request({hostname: host, port: 80, path: '/'}, function(res) {
    res.on('data', function(chunk) {
        total += chunk;
        if(chunk.toString().indexOf('index,nofollow') == -1) {
            // do stuff
        } else {
            /*
             * WHAT TO DO HERE???
             * how to close this res/req?
             * close this request (goto res.end or req.end????
             */
        }
    }).on('end', function() {
        // do stuff
    });
}).on('error', function(e) {
    // do stuff
    console.log("Got error: " + e.message);
});

The only thing I can’t figure out is to quit that connection. Or stop retrieving data because i don’t need it..

req.end(); doesn’t work.. it keeps continuing with retrieving data/chunks..
(in my test I get 14 chunks, but at the first chunk I already know i don’t need the other chunks, so I want to quit the request/response).

I now have a boolean that skips analyzing the others chunks, but in my opinion I’m better of skipping retrieving the data?

What function to call? Or is it impossible because it needs to retrieve everything?

  • 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-17T15:31:17+00:00Added an answer on June 17, 2026 at 3:31 pm

    I haven’t tested it yet, putting this in your else block should work: res.removeAllListeners('data');

    Basically your res is a child of EventEmitter Object. By calling removeAllListeners('data') on it, all the handlers which are bound to data event will be removed and the callback won’t execute anymore. But you will still have to wait for all the data events to pass before end or error events are emitted on the request.

    Also read nodejs EventEmitter documentation for more info.

    Update:

    You might as well try and emit end or close event on res object in your else block, like this: res.emit('end'); or res.emit('close');. The documentation on clientRespone object for end event says that it is

    Emitted exactly once for each response. After that, no more ‘data’ events will be emitted on the response.

    • 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 have a jquery bug and I've been looking for hours now, I can't
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.