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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:53:25+00:00 2026-06-03T07:53:25+00:00

I am working on a Flatiron Union-based app, and it seems that the simple

  • 0

I am working on a Flatiron Union-based app, and it seems that the simple logger I am developing logs before the routes are run, so it does not accurately report what happened. I took the logger sample code from the Union examples. Here’s a stripped down code sample:

 var
   union = require('union')
   , server;

 server = union.createServer({
   before: [ function (req,res) {
     console.log('before');
     res.writeHead(404, {"Content-Type": "text/plain"});
     res.end("Hello World");
   } ],
   after: [
     function LoggerStream() {
         var stream   = new union.ResponseStream();
         stream.once("pipe", function (req) {
           console.log({res: this.res.statusCode, method: this.req.method});
         });
         return stream;
     }
   ]
 });

 server.listen(8800);
 console.log('union running on 8800');

Here’s what appears in my console:

 $ DEBUG=*  node ./union.js
 union running on 8800
 { res: 200, method: 'GET' }
 before

Note that the reported status is 200 when the http server actually returned a 404.

Why is this running out of order?

  • 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-03T07:53:27+00:00Added an answer on June 3, 2026 at 7:53 am

    Here’s a recent reply to your question from our mailing list by indexzero:

    Stuart,

    This is actually expected behavior. A pipe chain is constructed by a
    union.RoutingStream instance from:

    union.ResponseStream() –> after0 –> after1 –> after2 –> … –>
    aftern –> http.Response() (see
    https://github.com/flatiron/union/blob/master/lib/routing-stream.js#L74-83)

    So the pipe event on every Stream in the after chain is invoked
    immediately, but everyone of those Streams has an opportunity to
    modify the data sent to the response by implementing their own .pipe()
    method.

    So for example if your LoggingStream was

    var stream = new union.ResponseStream(); stream.once(“data”,
    function (req) { console.log({res: this.res.statusCode, method:
    this.req.method}); }); return stream;

    You would see the console.log statements fire in the order you expect.
    It might be useful to read Max Ogden’s recent blog post on Streams in
    node.js and how they work: http://maxogden.com/node-streams

    Cheers, Charlie

    If you have more questions, you can find us on github, irc (#nodejitsu on freenode) and our mailing list at flatironjs@googlegroups.com . 🙂

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

Sidebar

Related Questions

Working with phoneGap implementing drawing with Canvas. The catch we've run into is that
Working on a mobile app that needs to use a public API for accessing
Working on an html5 app for a touchscreen windows xp computer that will be
Working on a bunch of forms at the moment and I'm finding that I
Working on a website that has Employee and Branch entities, using a database table
Working on a rather small, and simple layout, I decided to use Meyer's CSS
Working on a movie website and would love to find an API that I
Working on a new app and using restful-authentication. I was trying to make it
Working in an app where a page_title method was defined in application_helper.rb as such:
Working on an extension that use the new experimental devtools apis. How do you

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.