Skip to content

Latest commit

 

History

History

stream-view

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

stream-view

This is a "Hello World" application, using a view that inherits from a Readable stream.

To invoke, the following command begins listening on localhost:3000.

node app.js

To see results:

http://localhost:3000

Interesting points

  1. The main function of app.js instantiates a "View" from the view.js file.
  2. The View overrides the Readable's _read() function with an empty function.
  3. The View also overrides the Readable's render() function to do the following:
  4. Immediately push out the text for the <head> of the page
  5. Yield to a function that will ultimately (in the next tick) return the "Hello World" text. The render() function pauses at that point.
  6. When that function returns, render() resumes, and assigns the return value to the body variable
  7. Push out the returned text wrapped in <body> tags
  8. Push out the closing </html> tag and
  9. Close the connection with push(null)