examples/stream-view
Kevin Rambaud fc7f25a73f Fix mocha version and unit tests (#117)
* Remove duplicate supertest dependency

* Fix mocha version

* Add an after statement to close koa app instance after running tests
2018-01-24 19:10:06 +08:00
..
2017-05-30 20:44:57 +08:00
2016-07-22 22:12:18 +02:00
2017-05-30 20:44:57 +08:00

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)