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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:47:00+00:00 2026-05-24T10:47:00+00:00

First time working with NodeJS (yes, it’s awesome) and also using Express as well.

  • 0

First time working with NodeJS (yes, it’s awesome) and also using Express as well. Got the web app / service working great but I run in to problems when trying to make more than one http request. Here’s a video of how the app causes 2 http requests – http://screencast.com/t/yFKdIajs0XD – as you can see I click on ‘articles’ it loads an rss feed, then click videos and it loads a youtube feed – both work just fine but after the second call is made it throws an exception. I get the following when I attempt two separate http requests using node’s http module:

http.js:527
throw new Error("Can't set headers after they are sent.");
      ^

Error: Can't set headers after they are sent.
at ServerResponse.<anonymous> (http.js:527:11)
at ServerResponse.setHeader (/Users/rickblalock/node/auti_node/node_modules/express/node_modules/connect/lib/patch.js:47:22)
at /Users/rickblalock/node/auti_node/node_modules/express/node_modules/connect/lib/middleware/errorHandler.js:72:19
at [object Object].<anonymous> (fs.js:107:5)
at [object Object].emit (events.js:61:17)
at afterRead (fs.js:878:12)
at wrapper (fs.js:245:17)

Sample code provided here:
Using my controller module to render the request – http://pastie.org/2317698
One of the tabs (article tab) – the video code is identical minus referencing a video feed: http://pastie.org/2317731

  • 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-24T10:47:01+00:00Added an answer on May 24, 2026 at 10:47 am

    try using the “end” event not “data” like this:

    var data = "";
    
    app.get('/', function(req, res){
    
        var options = {
              host: 'http://www.engadget.com',
              path: '/rss.xml',
              method: 'GET'
            };
    
        if (data === "") {
            var myReq = http.request(options, function(myRes) {
                myRes.setEncoding('utf8');
    
                myRes.on('data', function(chunk) {
                    console.log("request on data ");
                    data += chunk;
                });
    
                myRes.on('end', function () {
                    console.log("request on END");
                    res.render('index', {
                        title: 'Express',
                        data: data
                    });
                });
            });
    
            myReq.write('data\n');
            myReq.end();
        }
        else {
            res.render('index', {
                title: 'Express',
                data: data
            });
        }
    });
    

    old answer

    i also think that this is the culprit:

    var req = http.request(options, function(res) {
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
          parseArticle(chunk);
        });
    });
    req.write('data\n');
    req.end();
    

    the first line is async so everything inside the callback is called after you do req.write() and req.end()
    put these two lines into the callback.

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

Sidebar

Related Questions

I'm working for the first time with Forms Authentication, I'm using an example from
I am working on a Java project using Netbeans for the first time. I
I am now working on a web application project for the first time, the
I'm working with jQuery for the first time and need some help. I have
I'm working with caching and persistence for the first time. I have a user
I'm working with embedded C for the first time. Although my C is rusty,
I'm just getting started working with foreign keys for the first time and I'm
The first time I load the website in the production web server, it start
We're building a very content rich site in Drupal. It's my first time working
First-timer here, I hope I explain this well enough... PHP/Smarty, I'm working on a

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.