node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


build status


Middleware to append some text to the body of outgoing responses.

Includes pre-filter and post-filter functions so that it doesn't have to buffer a request we don't care about, and can selectively append text based on the body of the response.


The basic usage:

var connect = require('connect');
var appender = require('connect-appender');
var app = connect()
  .use(function(req, res) {

More advanced, choosing which request/responses to affect:

var connect = require('connect');
var appender = require('..');
var prefilter = function(req, res) {
  // called before the request is passed through 
  //  determines whether to wrap the resulting response 
  return /only_here/.test(req.url);
var postfilter = function(spec) {
  // called as the response is ending 
  //  determines whether to append the text 
  return !(/not_here/.test(spec.request.url));
var trailer = function(spec) {
  // called to determine what text to append 
  return 'zorz\n' + spec.statusCode + '\n';
// Spec is generated when ending the response, and looks like: { 
//   request: http.ServerRequest, 
//   response: http.ServerResponse, 
//   statusCode: number, 
//   headers: Object.<string, string>, 
//   output: string 
// } 
var app = connect()
  .use(appender(trailer, prefilter, postfilter))
  .use(function(req, res) {
    res.end('[' + req.url + ']: response\n');


  • response.write() with different encodings


  • init: npm install
  • tests: npm test
  • dev: npm run-script tdd

NOTE: The tests rely on custom forks of: connect, grunt, and grunt-simple-mocha.