Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>request</code> is an instance of <code>http.IncomingMessage</code>, which implements the <code>stream.Readable</code> interface.</p> <p>Documentation at <a href="http://nodejs.org/api/stream.html#stream_event_end">http://nodejs.org/api/stream.html#stream_event_end</a> says:</p> <blockquote> <h3>Event: 'end'</h3> <p>This event fires when no more data will be provided.</p> <p>Note that the end event will not fire unless the data is completely consumed. This can be done by switching into flowing mode, or by calling <code>read()</code> repeatedly until you get to the end.</p> <pre><code>var readable = getReadableStreamSomehow(); readable.on('data', function(chunk) { console.log('got %d bytes of data', chunk.length); }) readable.on('end', function() { console.log('there will be no more data.'); }); </code></pre> </blockquote> <p>So in your case, because you don't use either <code>read()</code> or subscribe to the <code>data</code> event, the <code>end</code> event will never fire.</p> <p>Adding</p> <pre><code> request.on("data",function() {}) // a noop </code></pre> <p>within the event listener would probably make the code work.</p> <p>Note that using the request object as a stream is only necessary for when the HTTP request has a body. E.g. for PUT and POST requests. Otherwise you can consider the request to have finished already, and just send out the data.</p> <p>If the code your posting is taken literally from some other site, it may be that this code example was based on Node 0.8. In Node 0.10, there have been changes in how streams work. </p> <p>From <a href="http://blog.nodejs.org/2012/12/20/streams2/">http://blog.nodejs.org/2012/12/20/streams2/</a></p> <blockquote> <p>WARNING: If you never add a 'data' event handler, or call resume(), then it'll sit in a paused state forever and never emit 'end'. So the code you posted would have worked on Node 0.8.x, but does not in Node 0.10.x.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload