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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:59:45+00:00 2026-06-09T15:59:45+00:00

I’m looking to write a NPM module that builds on top of node-http-proxy but

  • 0

I’m looking to write a NPM module that builds on top of node-http-proxy but adds caching support, like squid/varnish, but in node.js.

In my head, it will work like this:

  • My NPM module won’t depend on http-proxy, with will just “wrap” any callback given to http.createServer. The idea is that you combine this with http-proxy, but it doesn’t assume that.
  • It will look at the req and if it has a cached version, it will serve that.
  • If it doesn’t, it will delegate to the original callback, inspecting the response to see if it can be cached.
  • Caching takes place, and the actual response is returned.

The logic is pretty straightforward, but I’m not very familiar with node.js internals and concepts and I’m struggling to even figure out how to get the content of the response.

Given this example:

var http = require('http');

http.createServer(function(req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' })
  res.write('Hello World!');
  res.end();
}).listen(80);

How would I get the data back from that response object? Ideally I’d just ‘observe’ the response and process data as it’s written to it, rather than retrospectively pull data back out of it.

I tried doing:

res.on('data', function(chunk) {
  console.log('Data written: ' + chunk);
});

But that never seems to get called.

I then tried:

res.connection.on('data', function(chunk) {
  console.log('Data written: ' + chunk);
});

But that just dumped the request data, not the response data. What’s the correct way to filter response data, assuming you know nothing about how the response was generated?

If I’m expressing my complete lack of understanding of node and should read some sort of “A newbie guide to node.js concepts” please direct me to this. I’m not lazy, I’m just lost.

EDIT | Looks like I can method-swizzle write() and writeHead() on the response to intercept the invocations to them, but this feels wrong.

  • 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-09T15:59:46+00:00Added an answer on June 9, 2026 at 3:59 pm

    Looks like redifinition write and writeHead methods of ServerResponse the only way to do that. Node API has no native events to handle outgoing data.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping 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.