Permalink
Browse files

Regenerated book

  • Loading branch information...
1 parent 5ab4edb commit 3c7e6d3642f31b89138a8b26d9561307e4fab26c @jimschubert committed May 3, 2011
Showing with 8 additions and 9 deletions.
  1. BIN docs/book.epub
  2. +8 −9 docs/book.html
  3. BIN docs/book.mobi
  4. BIN docs/book.pdf
View
Binary file not shown.
View
@@ -1005,15 +1005,14 @@ <h2 id="readable_Streams">Readable Streams</h2>
// Do something with the Buffer
});</code></pre>
-<p>As we know, we can call <code>toString()</code> a buffer to return a string representation of the binary data, however in the case of streams if desired we may call <code>setEncoding()</code> on the stream,
-after which the <em>data</em> event will emit strings.</p>
+<p>As we know, we can call <code>toString()</code> on a buffer to return a string representation of the binary data. In the case of streams, if desired, we may call <code>setEncoding()</code> on the stream, after which the <em>data</em> event will emit strings.</p>
<pre><code>req.setEncoding('utf8');
req.on('data', function(str){
// Do something with the String
});</code></pre>
-<p>Another import event is the <em>end</em> event, which represents the ending of <em>data</em> events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we <strong>POST</strong> "hello world", our response will be "hello world".</p>
+<p>Another important event is the <em>end</em> event, which represents the ending of <em>data</em> events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we <strong>POST</strong> "hello world", our response will be "hello world".</p>
<pre><code>// streams/echo.js
var http = require('http');
@@ -1275,7 +1274,7 @@ <h3 id="creating_the_module">Creating the module</h3>
<p>Now that we have a plan in place for the interaction with the module, let's take a look at the three functions, <code>getFile()</code>, <code>getHtml()</code>, and <code>run()</code>.</p>
-<p><strong> getFile(request) </strong></p>
+<h3 id="getFile">getFile(request)</h3>
<p>The <code>getFile()</code> function assumes that all requests occur at the base of the server's uri. It also ignores requests for <code>/favicon.ico</code> and for the base uri <code>/</code>. It then builds a full path to the file and attempts to read the file in a single blocking call. This blocking call helps ensure that we're passing data correctly to the Markdown module.</p>
@@ -1302,7 +1301,7 @@ <h3 id="creating_the_module">Creating the module</h3>
<p>This function uses the same pattern of identifying a callback as the node libraries. The <code>noop()</code> function is defined as <code>var noop = function() { };</code> which saves us from creating numerous empty callbacks and checking for functions where those callbacks are required. For those unfamiliar with the term <em>noop</em>, it means the function performs <strong>no op</strong>eration.</p>
-<p><strong> getHtml(request) </strong></p>
+<h3 id="getHtml">getHtml(request)</h3>
<p>The second function in our module performs the conversion between markdown and html. It does this in the callack to the <code>getFile()</code> function, transforms the markdown to html, and passes the result to its own callback. </p>
@@ -1329,7 +1328,7 @@ <h3 id="creating_the_module">Creating the module</h3>
<p>If there are any errors, it returns a string: "Nothing to see here!" A message like this usually accompanies a <code>404 - Not Found</code> HTTP status, but we're keeping this pretty simple.</p>
-<p><strong> run() </strong></p>
+<h3 id="run">run()</h3>
<p>The run function requires the following server to be created. The <code>requestListener</code> function calls <code>getHtml</code> and writes the html to the response. Here, we're using a buffer to get the proper byte length and attempt to output a properly-encoded html string.</p>
@@ -1366,7 +1365,7 @@ <h3 id="creating_the_module">Creating the module</h3>
<p>Notice how we've moved the console logging to the <code>server.listen</code> callback. This makes more sense than the procedural example from before- if the port isn't available and <code>server.listen</code> throws an error, you don't want to tell the developer that the server has started! This is how things should be programmed, and it's part of what makes node.js so awesome.</p>
-<p><strong> Exposing <code>run()</code> </strong></p>
+<h3 id="exposing_run_">Exposing `run()`</h3>
<p>The last thing to do to make our module run is to expose the run function. To revisit from the <em>Modules</em> chapter, you can do this a few ways:</p>
@@ -1382,15 +1381,15 @@ <h3 id="creating_the_module">Creating the module</h3>
<p>There's no 'correct' method, and each has it's benefits. Please refer to the <em>Best Practices</em> section for more information.</p>
-<p><strong> Run it! </strong></p>
+<h3 id="run_it_">Run it!</h3>
<pre><code>$ node src/http/server_example.js
Server is running on http://localhost:9222
Hit CTRL+C to shutdown the http server</code></pre>
<p>After receiving the output to confirm the server is running, visit <a href="http://localhost:9222">http://localhost:9222</a> to check it out. Then, hit <code>CTRL+C</code> to be sure the server's <code>close</code> function is working as expected.</p>
-<p><strong> Where are the events? </strong></p>
+<h3 id="where_are_the_events_">Where are the events?</h3>
<p>You may have noticed that we met only half of the requirements with the above implementation of our server. To expose events, our <code>run</code> method would have to inherit from <code>EventEmitter</code>. That doesn't <em>really</em> make sense. For the sake of simplicity and brevity, we previously only had three methods. We had no class-like objects, and we didn't touch an object's prototype. Also, the three methods we did have didn't make good use of callbacks. So, there is another take on this example at <em>./src/http/server/server2.js</em>.</p>
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 3c7e6d3

Please sign in to comment.