diff --git a/book.html b/book.html index 8188873..c627652 100644 --- a/book.html +++ b/book.html @@ -287,12 +287,12 @@

Registering Module Compilers

}; -

Next we have to "register" the extension to assign out compiler. As previously mentioned our compiler lives at ./compiler/extended.js so we are requiring it in, and passing the compile() method to require.registerExtension() which simply expects a function accepting a string, and returning a string of JavaScript.

+

Next we have to "register" the extension to assign our compiler. As previously mentioned, our compiler lives at ./compiler/extended.js; so we are requiring it, passing the compile() method to require.registerExtension() (which simply expects a function accepting a string), and returning a string of JavaScript.

require.registerExtension('.ejs', require('./compiler/extended').compile);
 
-

Now when we require our example, the ".ejs" extension is detected, and will pass the contents through our compiler, and everything works as expected.

+

Now when we require our example, the ".ejs" extension is detected, and will pass the contents through our compiler.

var example = require('./compiler/example');
 console.dir(example)
@@ -307,15 +307,15 @@ 

Registering Module Compilers

Globals

-

As we have learnt node's module system discourages the use of globals, however node provides a few important globals for use to utilize. The first and most important is the process global which exposes process manipulation such as signalling, exiting, the process id (pid), and more. Other globals help drive to be similar to other familiar JavaScript environments such as the browser, by providing a console object.

+

As we have learnt, node's module system discourages the use of globals; however node provides a few important globals for use to utilize. The first and most important is the process global, which exposes process manipulation such as signalling, exiting, the process id (pid), and more. Other globals, such as the console object, are provided to those used to writing JavaScript for web browsers.

console

-

The console object contains several methods which are used to output information to stdout or stderr. Let's take a look at what each method does.

+

The console object contains several methods which are used to output information to stdout or stderr. Let's take a look at what each method does:

console.log()

-

The most frequently used console method is console.log() simply writing to stdout with a line feed (\n). Currently aliased as console.info().

+

The most frequently used console method is console.log(), which simply writes to stdout and appends a line feed (\n). Currently aliased as console.info().

console.log('wahoo');
 // => wahoo
@@ -349,24 +349,24 @@ 

console.assert()

process

-

The process object is plastered with goodies, first we will take a look -at some properties that provide information about the node process itself.

+

The process object is plastered with goodies. First we will take a look +at some properties that provide information about the node process itself:

process.version

-

The version property contains the node version string, for example "v0.1.103".

+

The node version string, for example "v0.1.103".

process.installPrefix

-

Exposes the installation prefix, in my case "/usr/local", as node's binary was installed to "/usr/local/bin/node".

+

The installation prefix. In my case "/usr/local", as node's binary was installed to "/usr/local/bin/node".

process.execPath

-

Path to the executable itself "/usr/local/bin/node".

+

The path to the executable itself "/usr/local/bin/node".

process.platform

-

Exposes a string indicating the platform you are running on, for example "darwin".

+

The platform you are running on. For example, "darwin".

process.pid

@@ -374,7 +374,7 @@

process.pid

process.cwd()

-

Returns the current working directory, for example:

+

Returns the current working directory. For example:

cd ~ && node
 node> process.cwd()
@@ -402,11 +402,11 @@ 

process.getgid()

process.setgid()

-

Similar to process.setuid() however operates on the group, also accepting a numerical value or string representation. For example process.setgid(20) or process.setgid('www').

+

Similar to process.setuid() however operates on the group, also accepting a numerical value or string representation. For example, process.setgid(20) or process.setgid('www').

process.env

-

An object containing the user's environment variables, for example:

+

An object containing the user's environment variables. For example:

{ PATH: '/Users/tj/.gem/ruby/1.8/bin:/Users/tj/.nvm/current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin'
 , PWD: '/Users/tj/ebooks/masteringnode'
@@ -425,7 +425,7 @@ 

process.argv

When executing a file with the node executable process.argv provides access to the argument vector, the first value being the node executable, second being the filename, and remaining values being the arguments passed.

-

For example our source file ./src/process/misc.js can be executed by running:

+

For example, our source file ./src/process/misc.js can be executed by running:

$ node src/process/misc.js foo bar baz
 
@@ -442,11 +442,11 @@

process.argv

process.exit()

-

The process.exit() method is synonymous with the C function exit(), in which a exit code > 0 is passed indicating failure, or 0 to indicate success. When invoked the exit event is emitted, allowing a short time for arbitrary processing to occur before process.reallyExit() is called with the given status code.

+

The process.exit() method is synonymous with the C function exit(), in which an exit code > 0 is passed to indicate failure, or 0 is passed to indicate success. When invoked, the exit event is emitted, allowing a short time for arbitrary processing to occur before process.reallyExit() is called with the given status code.

process.on()

-

The process itself is an EventEmitter, allowing you to do things like listen for uncaught exceptions, via the uncaughtException event:

+

The process itself is an EventEmitter, allowing you to do things like listen for uncaught exceptions via the uncaughtException event:

process.on('uncaughtException', function(err){
     console.log('got an error: %s', err.message);
@@ -460,7 +460,7 @@ 

process.on()

process.kill()

-

process.kill() method sends the signal passed to the given pid, defaulting to SIGINT. In our example below we send the SIGTERM signal to the same node process to illustrate signal trapping, after which we output "terminating" and exit. Note that our second timeout of 1000 milliseconds is never reached.

+

process.kill() method sends the signal passed to the given pid, defaulting to SIGINT. In the example below, we send the SIGTERM signal to the same node process to illustrate signal trapping, after which we output "terminating" and exit. Note that the second timeout of 1000 milliseconds is never reached.

process.on('SIGTERM', function(){
     console.log('terminating');
@@ -479,7 +479,7 @@ 

process.kill()

errno

-

The process object is host of the error numbers, these reference what you would find in C-land, for example process.EPERM represents a permission based error, while process.ENOENT represents a missing file or directory. Typically these are used within bindings to bridge the gap between C++ and JavaScript, however useful for handling exceptions as well:

+

The process object is host of the error numbers, which reference what you would find in C-land. For example, process.EPERM represents a permission based error, while process.ENOENT represents a missing file or directory. Typically these are used within bindings to bridge the gap between C++ and JavaScript, but they're useful for handling exceptions as well:

if (err.errno === process.ENOENT) {
     // Display a 404 "Not Found" page
@@ -491,11 +491,11 @@ 

errno

Events

-

The concept of an "event" is crucial to node, and used greatly throughout core and 3rd-party modules. Node's core module events supplies us with a single constructor, EventEmitter.

+

The concept of an "event" is crucial to node, and is used heavily throughout core and 3rd-party modules. Node's core module events supplies us with a single constructor, EventEmitter.

Emitting Events

-

Typically an object inherits from EventEmitter, however our small example below illustrates the api. First we create an emitter, after which we can define any number of callbacks using the emitter.on() method which accepts the name of the event, and arbitrary objects passed as data. When emitter.emit() is called we are only required to pass the event name, followed by any number of arguments, in this case the first and last name strings.

+

Typically an object inherits from EventEmitter, however our small example below illustrates the API. First we create an emitter, after which we can define any number of callbacks using the emitter.on() method, which accepts the name of the event and arbitrary objects passed as data. When emitter.emit() is called, we are only required to pass the event name, followed by any number of arguments (in this case the first and last name strings).

var EventEmitter = require('events').EventEmitter;
 
@@ -511,9 +511,9 @@ 

Emitting Events

Inheriting From EventEmitter

-

A perhaps more practical use of EventEmitter, and commonly used throughout node is to inherit from it. This means we can leave EventEmitter's prototype untouched, while utilizing its api for our own means of world domination!

+

A more practical and common use of EventEmitter is to inherit from it. This means we can leave EventEmitter's prototype untouched while utilizing its API for our own means of world domination!

-

To do so we begin by defining the Dog constructor, which of course will bark from time to time, also known as an event.

+

To do so, we begin by defining the Dog constructor, which of course will bark from time to time (also known as an event).

var EventEmitter = require('events').EventEmitter;
 
@@ -522,12 +522,12 @@ 

Inheriting From EventEmitter

}
-

Here we inherit from EventEmitter, so that we may use the methods provided such as EventEmitter#on() and EventEmitter#emit(). If the __proto__ property is throwing you off, no worries! we will be touching on this later.

+

Here we inherit from EventEmitter so we can use the methods it provides, such as EventEmitter#on() and EventEmitter#emit(). If the __proto__ property is throwing you off, don't worry, we'll be coming back to this later.

Dog.prototype.__proto__ = EventEmitter.prototype;
 
-

Now that we have our Dog set up, we can create .... simon! When simon barks we can let stdout know by calling console.log() within the callback. The callback it-self is called in context to the object, aka this.

+

Now that we have our Dog set up, we can create... Simon! When Simon barks, we can let stdout know by calling console.log() within the callback. The callback itself is called in the context of the object (aka this).

var simon = new Dog('simon');
 
@@ -536,7 +536,7 @@ 

Inheriting From EventEmitter

});
-

Bark twice a second:

+

Bark twice per second:

setInterval(function(){
     simon.emit('bark');
@@ -545,7 +545,7 @@ 

Inheriting From EventEmitter

Removing Event Listeners

-

As we have seen event listeners are simply functions which are called when we emit() an event. Although not seen often we can remove these listeners by calling the removeListener(type, callback) method. In the example below we emit the message "foo bar" every 300 milliseconds, which has the callback of console.log(). After 1000 milliseconds we call removeListener() with the same arguments that we passed to on() originally. To compliment this method is removeAllListeners(type) which removes all listeners associated to the given type.

+

As we have seen, event listeners are simply functions which are called when we emit() an event. We can remove these listeners by calling the removeListener(type, callback) method, although this isn't seen often. In the example below we emit the message "foo bar" every 300 milliseconds, which has a callback of console.log(). After 1000 milliseconds, we call removeListener() with the same arguments that we passed to on() originally. We could also have used removeAllListeners(type), which removes all listeners registered to the given type.

var EventEmitter = require('events').EventEmitter;
 
@@ -565,9 +565,9 @@ 

Removing Event Listeners

Buffers

-

To handle binary data, node provides us with the global Buffer object. Buffer instances represent memory allocated independently to that of V8's heap. There are several ways to construct a Buffer instance, and many ways you can manipulate it's data.

+

To handle binary data, node provides us with the global Buffer object. Buffer instances represent memory allocated independently of V8's heap. There are several ways to construct a Buffer instance, and many ways you can manipulate its data.

-

The simplest way to construct a Buffer from a string is to simply pass a string as the first argument. As you can see by the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.

+

The simplest way to construct a Buffer from a string is to simply pass a string as the first argument. As you can see in the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.

var hello = new Buffer('Hello');
 
@@ -578,7 +578,7 @@ 

Buffers

// => "Hello"
-

By default the encoding is "utf8", however this can be specified by passing as string as the second argument. The ellipsis below for example will be printed to stdout as the '&' character when in "ascii" encoding.

+

By default, the encoding is "utf8", but this can be overridden by passing a string as the second argument. For example, the ellipsis below will be printed to stdout as the "&" character when in "ascii" encoding.

var buf = new Buffer('…');
 console.log(buf.toString());
@@ -589,12 +589,12 @@ 

Buffers

// => &
-

An alternative method is to pass an array of integers representing the octet stream, however in this case functionality equivalent.

+

An alternative (but in this case functionality equivalent) method is to pass an array of integers representing the octet stream.

var hello = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
 
-

Buffers can also be created with an integer representing the number of bytes allocated, after which we may call the write() method, providing an optional offset and encoding. As shown below we provide the offset of 2 bytes to our second call to write(), buffering "Hel", and then we continue on to write another two bytes with an offset of 3, completing "Hello".

+

Buffers can also be created with an integer representing the number of bytes allocated, after which we can call the write() method, providing an optional offset and encoding. Below, we provide an offset of 2 bytes to our second call to write() (buffering "Hel") and then write another two bytes with an offset of 3 (completing "Hello").

var buf = new Buffer(5);
 buf.write('He');
@@ -604,7 +604,7 @@ 

Buffers

// => "Hello"
-

The .length property of a buffer instance contains the byte length of the stream, opposed to JavaScript strings which will simply return the number of characters. For example the ellipsis character '…' consists of three bytes, however the buffer will respond with the byte length, and not the character length.

+

The .length property of a buffer instance contains the byte length of the stream, as opposed to native strings, which simply return the number of characters. For example, the ellipsis character '…' consists of three bytes, so the buffer will respond with the byte length (3), and not the character length (1).

var ellipsis = new Buffer('…', 'utf8');
 
@@ -618,16 +618,16 @@ 

Buffers

// => <Buffer e2 80 a6>
-

When dealing with JavaScript strings, we may pass it to the Buffer.byteLength() method to determine it's byte length.

+

To determine the byte length of a native string, pass it to the Buffer.byteLength() method.

-

The api is written in such a way that it is String-like, so for example we can work with "slices" of a Buffer by passing offsets to the slice() method:

+

The API is written in such a way that it is String-like. For example, we can work with "slices" of a Buffer by passing offsets to the slice() method:

var chunk = buf.slice(4, 9);
 console.log(chunk.toString());
 // => "some"
 
-

Alternatively when expecting a string we can pass offsets to Buffer#toString():

+

Alternatively, when expecting a string, we can pass offsets to Buffer#toString():

var buf = new Buffer('just some data');
 console.log(buf.toString('ascii', 4, 9));
@@ -637,7 +637,7 @@ 

Buffers

Streams

-

Streams are an important concept in node. The stream api is a unified way to handle stream-like data, for example data can be streamed to a file, streamed to a socket to respond to an HTTP request, or a stream can be read-only such as reading from stdin. However since we will be touching on stream specifics in later chapters, for now we will concentrate on the api.

+

Streams are an important concept in node. The stream API is a unified way to handle stream-like data. For example, data can be streamed to a file, streamed to a socket to respond to an HTTP request, or streamed from a read-only source such as stdin. For now, we'll concentrate on the API, leaving stream specifics to later chapters.

Readable Streams

@@ -648,8 +648,7 @@

Readable Streams

});
-

As we know, we can call toString() a buffer to return a string representation of the binary data, however in the case of streams if desired we may call setEncoding() on the stream, -after which the data event will emit strings.

+

As we know, we can call toString() on a buffer to return a string representation of the binary data. Likewise, we can call setEncoding() on a stream, after which the data event will emit strings.

req.setEncoding('utf8');
 req.on('data', function(str){
@@ -657,7 +656,7 @@ 

Readable Streams

});
-

Another import event is the end event, which represents the ending of data events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we POST "hello world", our response will be "hello world".

+

Another important event is end, which represents the ending of data events. For example, here's an HTTP echo server, which simply "pumps" the request body data through to the response. So if we POST "hello world", our response will be "hello world".

var http = require('http');
 
@@ -672,7 +671,7 @@ 

Readable Streams

}).listen(3000);
-

The sys module actually has a function designed specifically for this "pumping" action, aptly named sys.pump(), which accepts a read stream as the first argument, and write stream as the second.

+

The sys module actually has a function designed specifically for this "pumping" action, aptly named sys.pump(). It accepts a read stream as the first argument, and write stream as the second.

var http = require('http'),
     sys = require('sys');
@@ -686,11 +685,11 @@ 

Readable Streams

File System

-

To work with the filesystem, node provides the 'fs' module. The commands follow the POSIX operations, with most methods supporting an asynchronous and synchronous method call. We will look at how to use both and then establish which is the better option.

+

To work with the filesystem, node provides the "fs" module. The commands emulate the POSIX operations, and most methods work synchronously or asynchronously. We will look at how to use both, then establish which is the better option.

Working with the filesystem

-

Lets start with a basic example of working with the filesystem, this example creates a directory, it then creates a file in it. Once the file has been created the contents of the file are written to console:

+

Lets start with a basic example of working with the filesystem. This example creates a directory, creates a file inside it, then writes the contents of the file to console:

var fs = require('fs');
 
@@ -709,7 +708,7 @@ 

Working with the filesystem

});
-

As evident in the example above, each callback is placed in the previous callback - this is what is referred to as chainable callbacks. When using asynchronous methods this pattern should be used, as there is no guarantee that the operations will be completed in the order that they are created. This could lead to unpredictable behavior.

+

As evident in the example above, each callback is placed in the previous callback — these are referred to as chainable callbacks. This pattern should be followed when using asynchronous methods, as there's no guarantee that the operations will be completed in the order they're created. This could lead to unpredictable behavior.

The example can be rewritten to use a synchronous approach:

@@ -720,12 +719,11 @@

Working with the filesystem

console.log(data);
-

It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections and other events.

+

It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections or other events.

File information

-

The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we - are working with. In this example we are getting all the file objects in a directory and displaying whether they are a file or a +

The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we're working with. In this example, we're getting all the file objects in a directory and displaying whether they're a file or a directory object.

var fs = require('fs');
@@ -751,7 +749,7 @@ 

File information

Watching files

-

The fs.watchfile monitors a file and will fire the event whenever the file is changed.

+

The fs.watchfile method monitors a file and fires an event whenever the file is changed.

var fs = require('fs');
 
@@ -767,11 +765,11 @@ 

Watching files

});
-

A file can also be unwatched using the fs.unwatchFile method call. This is used once monitoring of a file is no longer required.

+

A file can also be unwatched using the fs.unwatchFile method call. This should be used once a file no longer needs to be monitored.

Nodejs Docs for further reading

-

The node api docs are very detailed and list all the possible filesystem commands +

The node API docs are very detailed and list all the possible filesystem commands available when working with Nodejs.

diff --git a/chapters/buffers.html b/chapters/buffers.html index 0b19f75..2298fcd 100644 --- a/chapters/buffers.html +++ b/chapters/buffers.html @@ -1,8 +1,8 @@

Buffers

-

To handle binary data, node provides us with the global Buffer object. Buffer instances represent memory allocated independently to that of V8's heap. There are several ways to construct a Buffer instance, and many ways you can manipulate it's data.

+

To handle binary data, node provides us with the global Buffer object. Buffer instances represent memory allocated independently of V8's heap. There are several ways to construct a Buffer instance, and many ways you can manipulate its data.

-

The simplest way to construct a Buffer from a string is to simply pass a string as the first argument. As you can see by the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.

+

The simplest way to construct a Buffer from a string is to simply pass a string as the first argument. As you can see in the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.

var hello = new Buffer('Hello');
 
@@ -13,7 +13,7 @@ 

Buffers

// => "Hello"
-

By default the encoding is "utf8", however this can be specified by passing as string as the second argument. The ellipsis below for example will be printed to stdout as the '&' character when in "ascii" encoding.

+

By default, the encoding is "utf8", but this can be overridden by passing a string as the second argument. For example, the ellipsis below will be printed to stdout as the "&" character when in "ascii" encoding.

var buf = new Buffer('…');
 console.log(buf.toString());
@@ -24,12 +24,12 @@ 

Buffers

// => &
-

An alternative method is to pass an array of integers representing the octet stream, however in this case functionality equivalent.

+

An alternative (but in this case functionality equivalent) method is to pass an array of integers representing the octet stream.

var hello = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
 
-

Buffers can also be created with an integer representing the number of bytes allocated, after which we may call the write() method, providing an optional offset and encoding. As shown below we provide the offset of 2 bytes to our second call to write(), buffering "Hel", and then we continue on to write another two bytes with an offset of 3, completing "Hello".

+

Buffers can also be created with an integer representing the number of bytes allocated, after which we can call the write() method, providing an optional offset and encoding. Below, we provide an offset of 2 bytes to our second call to write() (buffering "Hel") and then write another two bytes with an offset of 3 (completing "Hello").

var buf = new Buffer(5);
 buf.write('He');
@@ -39,7 +39,7 @@ 

Buffers

// => "Hello"
-

The .length property of a buffer instance contains the byte length of the stream, opposed to JavaScript strings which will simply return the number of characters. For example the ellipsis character '…' consists of three bytes, however the buffer will respond with the byte length, and not the character length.

+

The .length property of a buffer instance contains the byte length of the stream, as opposed to native strings, which simply return the number of characters. For example, the ellipsis character '…' consists of three bytes, so the buffer will respond with the byte length (3), and not the character length (1).

var ellipsis = new Buffer('…', 'utf8');
 
@@ -53,16 +53,16 @@ 

Buffers

// => <Buffer e2 80 a6>
-

When dealing with JavaScript strings, we may pass it to the Buffer.byteLength() method to determine it's byte length.

+

To determine the byte length of a native string, pass it to the Buffer.byteLength() method.

-

The api is written in such a way that it is String-like, so for example we can work with "slices" of a Buffer by passing offsets to the slice() method:

+

The API is written in such a way that it is String-like. For example, we can work with "slices" of a Buffer by passing offsets to the slice() method:

var chunk = buf.slice(4, 9);
 console.log(chunk.toString());
 // => "some"
 
-

Alternatively when expecting a string we can pass offsets to Buffer#toString():

+

Alternatively, when expecting a string, we can pass offsets to Buffer#toString():

var buf = new Buffer('just some data');
 console.log(buf.toString('ascii', 4, 9));
diff --git a/chapters/buffers.md b/chapters/buffers.md
index b0ce4f5..b62b80f 100644
--- a/chapters/buffers.md
+++ b/chapters/buffers.md
@@ -1,9 +1,9 @@
 
 # Buffers
 
- To handle binary data, node provides us with the global `Buffer` object. Buffer instances represent memory allocated independently to that of V8's heap. There are several ways to construct a `Buffer` instance, and many ways you can manipulate it's data.
+ To handle binary data, node provides us with the global `Buffer` object. `Buffer` instances represent memory allocated independently of V8's heap. There are several ways to construct a `Buffer` instance, and many ways you can manipulate its data.
  
-The simplest way to construct a `Buffer` from a string is to simply pass a string as the first argument. As you can see by the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.
+The simplest way to construct a `Buffer` from a string is to simply pass a string as the first argument. As you can see in the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.
 
     var hello = new Buffer('Hello');
     
@@ -13,7 +13,7 @@ The simplest way to construct a `Buffer` from a string is to simply pass a strin
     console.log(hello.toString());
     // => "Hello"
 
-By default the encoding is "utf8", however this can be specified by passing as string as the second argument. The ellipsis below for example will be printed to stdout as the '&' character when in "ascii" encoding.
+By default, the encoding is "utf8", but this can be overridden by passing a string as the second argument. For example, the ellipsis below will be printed to stdout as the "&" character when in "ascii" encoding.
 
     var buf = new Buffer('…');
     console.log(buf.toString());
@@ -23,11 +23,11 @@ By default the encoding is "utf8", however this can be specified by passing as s
     console.log(buf.toString());
     // => &
 
-An alternative method is to pass an array of integers representing the octet stream, however in this case functionality equivalent.
+An alternative (but in this case functionality equivalent) method is to pass an array of integers representing the octet stream.
 
     var hello = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
 
-Buffers can also be created with an integer representing the number of bytes allocated, after which we may call the `write()` method, providing an optional offset and encoding. As shown below we provide the offset of 2 bytes to our second call to `write()`, buffering "Hel", and then we continue on to write another two bytes with an offset of 3, completing "Hello".
+Buffers can also be created with an integer representing the number of bytes allocated, after which we can call the `write()` method, providing an optional offset and encoding. Below, we provide an offset of 2 bytes to our second call to `write()` (buffering "Hel") and then write another two bytes with an offset of 3 (completing "Hello").
 
     var buf = new Buffer(5);
     buf.write('He');
@@ -36,7 +36,7 @@ Buffers can also be created with an integer representing the number of bytes all
     console.log(buf.toString());
     // => "Hello"
 
-The `.length` property of a buffer instance contains the byte length of the stream, opposed to JavaScript strings which will simply return the number of characters. For example the ellipsis character '…' consists of three bytes, however the buffer will respond with the byte length, and not the character length.
+The `.length` property of a buffer instance contains the byte length of the stream, as opposed to native strings, which simply return the number of characters. For example, the ellipsis character '…' consists of three bytes, so the buffer will respond with the byte length (3), and not the character length (1).
 
     var ellipsis = new Buffer('…', 'utf8');
 
@@ -49,17 +49,16 @@ The `.length` property of a buffer instance contains the byte length of the stre
     console.log(ellipsis);
     // => 
 
-When dealing with JavaScript strings, we may pass it to the `Buffer.byteLength()` method to determine it's byte length.
+To determine the byte length of a native string, pass it to the `Buffer.byteLength()` method.
 
-The api is written in such a way that it is String-like, so for example we can work with "slices" of a `Buffer` by passing offsets to the `slice()` method:
+The API is written in such a way that it is String-like. For example, we can work with "slices" of a `Buffer` by passing offsets to the `slice()` method:
 
     var chunk = buf.slice(4, 9);
     console.log(chunk.toString());
     // => "some"
 
-Alternatively when expecting a string we can pass offsets to `Buffer#toString()`:
+Alternatively, when expecting a string, we can pass offsets to `Buffer#toString()`:
 
     var buf = new Buffer('just some data');
     console.log(buf.toString('ascii', 4, 9));
     // => "some"
-
diff --git a/chapters/events.html b/chapters/events.html
index 0d2b840..98b97c2 100644
--- a/chapters/events.html
+++ b/chapters/events.html
@@ -1,10 +1,10 @@
 

Events

-

The concept of an "event" is crucial to node, and used greatly throughout core and 3rd-party modules. Node's core module events supplies us with a single constructor, EventEmitter.

+

The concept of an "event" is crucial to node, and is used heavily throughout core and 3rd-party modules. Node's core module events supplies us with a single constructor, EventEmitter.

Emitting Events

-

Typically an object inherits from EventEmitter, however our small example below illustrates the api. First we create an emitter, after which we can define any number of callbacks using the emitter.on() method which accepts the name of the event, and arbitrary objects passed as data. When emitter.emit() is called we are only required to pass the event name, followed by any number of arguments, in this case the first and last name strings.

+

Typically an object inherits from EventEmitter, however our small example below illustrates the API. First we create an emitter, after which we can define any number of callbacks using the emitter.on() method, which accepts the name of the event and arbitrary objects passed as data. When emitter.emit() is called, we are only required to pass the event name, followed by any number of arguments (in this case the first and last name strings).

var EventEmitter = require('events').EventEmitter;
 
@@ -20,9 +20,9 @@ 

Emitting Events

Inheriting From EventEmitter

-

A perhaps more practical use of EventEmitter, and commonly used throughout node is to inherit from it. This means we can leave EventEmitter's prototype untouched, while utilizing its api for our own means of world domination!

+

A more practical and common use of EventEmitter is to inherit from it. This means we can leave EventEmitter's prototype untouched while utilizing its API for our own means of world domination!

-

To do so we begin by defining the Dog constructor, which of course will bark from time to time, also known as an event.

+

To do so, we begin by defining the Dog constructor, which of course will bark from time to time (also known as an event).

var EventEmitter = require('events').EventEmitter;
 
@@ -31,12 +31,12 @@ 

Inheriting From EventEmitter

}
-

Here we inherit from EventEmitter, so that we may use the methods provided such as EventEmitter#on() and EventEmitter#emit(). If the __proto__ property is throwing you off, no worries! we will be touching on this later.

+

Here we inherit from EventEmitter so we can use the methods it provides, such as EventEmitter#on() and EventEmitter#emit(). If the __proto__ property is throwing you off, don't worry, we'll be coming back to this later.

Dog.prototype.__proto__ = EventEmitter.prototype;
 
-

Now that we have our Dog set up, we can create .... simon! When simon barks we can let stdout know by calling console.log() within the callback. The callback it-self is called in context to the object, aka this.

+

Now that we have our Dog set up, we can create... Simon! When Simon barks, we can let stdout know by calling console.log() within the callback. The callback itself is called in the context of the object (aka this).

var simon = new Dog('simon');
 
@@ -45,7 +45,7 @@ 

Inheriting From EventEmitter

});
-

Bark twice a second:

+

Bark twice per second:

setInterval(function(){
     simon.emit('bark');
@@ -54,7 +54,7 @@ 

Inheriting From EventEmitter

Removing Event Listeners

-

As we have seen event listeners are simply functions which are called when we emit() an event. Although not seen often we can remove these listeners by calling the removeListener(type, callback) method. In the example below we emit the message "foo bar" every 300 milliseconds, which has the callback of console.log(). After 1000 milliseconds we call removeListener() with the same arguments that we passed to on() originally. To compliment this method is removeAllListeners(type) which removes all listeners associated to the given type.

+

As we have seen, event listeners are simply functions which are called when we emit() an event. We can remove these listeners by calling the removeListener(type, callback) method, although this isn't seen often. In the example below we emit the message "foo bar" every 300 milliseconds, which has a callback of console.log(). After 1000 milliseconds, we call removeListener() with the same arguments that we passed to on() originally. We could also have used removeAllListeners(type), which removes all listeners registered to the given type.

var EventEmitter = require('events').EventEmitter;
 
diff --git a/chapters/events.md b/chapters/events.md
index eea695c..bc65705 100644
--- a/chapters/events.md
+++ b/chapters/events.md
@@ -1,11 +1,11 @@
 
 # Events
 
- The concept of an "event" is crucial to node, and used greatly throughout core and 3rd-party modules. Node's core module _events_ supplies us with a single constructor, _EventEmitter_.
+ The concept of an "event" is crucial to node, and is used heavily throughout core and 3rd-party modules. Node's core module _events_ supplies us with a single constructor, _EventEmitter_.
 
 ## Emitting Events
 
-Typically an object inherits from _EventEmitter_, however our small example below illustrates the api. First we create an `emitter`, after which we can define any number of callbacks using the `emitter.on()` method which accepts the _name_ of the event, and arbitrary objects passed as data. When `emitter.emit()` is called we are only required to pass the event _name_, followed by any number of arguments, in this case the `first` and `last` name strings.
+Typically an object inherits from _EventEmitter_, however our small example below illustrates the API. First we create an `emitter`, after which we can define any number of callbacks using the `emitter.on()` method, which accepts the _name_ of the event and arbitrary objects passed as data. When `emitter.emit()` is called, we are only required to pass the event _name_, followed by any number of arguments (in this case the `first` and `last` name strings).
 
 	var EventEmitter = require('events').EventEmitter;
 
@@ -20,9 +20,9 @@ Typically an object inherits from _EventEmitter_, however our small example belo
 
 ## Inheriting From EventEmitter
 
-A perhaps more practical use of `EventEmitter`, and commonly used throughout node is to inherit from it. This means we can leave `EventEmitter`'s prototype untouched, while utilizing its api for our own means of world domination!
+A more practical and common use of `EventEmitter` is to inherit from it. This means we can leave `EventEmitter`'s prototype untouched while utilizing its API for our own means of world domination!
 
-To do so we begin by defining the `Dog` constructor, which of course will bark from time to time, also known as an _event_.
+To do so, we begin by defining the `Dog` constructor, which of course will bark from time to time (also known as an _event_).
 
 	var EventEmitter = require('events').EventEmitter;
 
@@ -30,11 +30,11 @@ To do so we begin by defining the `Dog` constructor, which of course will bark f
 	    this.name = name;
 	}
 
-Here we inherit from `EventEmitter`, so that we may use the methods provided such as `EventEmitter#on()` and `EventEmitter#emit()`. If the `__proto__` property is throwing you off, no worries! we will be touching on this later.
+Here we inherit from `EventEmitter` so we can use the methods it provides, such as `EventEmitter#on()` and `EventEmitter#emit()`. If the `__proto__` property is throwing you off, don't worry, we'll be coming back to this later.
 
 	Dog.prototype.__proto__ = EventEmitter.prototype;
 
-Now that we have our `Dog` set up, we can create .... simon! When simon barks we can let _stdout_ know by calling `console.log()` within the callback. The callback it-self is called in context to the object, aka `this`.
+Now that we have our `Dog` set up, we can create... Simon! When Simon barks, we can let _stdout_ know by calling `console.log()` within the callback. The callback itself is called in the context of the object (aka `this`).
 
 	var simon = new Dog('simon');
 
@@ -42,7 +42,7 @@ Now that we have our `Dog` set up, we can create .... simon! When simon barks we
 	    console.log(this.name + ' barked');
 	});
 
-Bark twice a second:
+Bark twice per second:
 
 	setInterval(function(){
 	    simon.emit('bark');
@@ -50,7 +50,7 @@ Bark twice a second:
 
 ## Removing Event Listeners
 
-As we have seen event listeners are simply functions which are called when we `emit()` an event. Although not seen often we can remove these listeners by calling the `removeListener(type, callback)` method. In the example below we emit the _message_ "foo bar" every `300` milliseconds, which has the callback of `console.log()`. After 1000 milliseconds we call `removeListener()` with the same arguments that we passed to `on()` originally. To compliment this method is `removeAllListeners(type)` which removes all listeners associated to the given _type_.
+As we have seen, event listeners are simply functions which are called when we `emit()` an event. We can remove these listeners by calling the `removeListener(type, callback)` method, although this isn't seen often. In the example below we emit the _message_ "foo bar" every `300` milliseconds, which has a callback of `console.log()`. After 1000 milliseconds, we call `removeListener()` with the same arguments that we passed to `on()` originally. We could also have used `removeAllListeners(type)`, which removes all listeners registered to the given _type_.
 
 	var EventEmitter = require('events').EventEmitter;
 
diff --git a/chapters/fs.html b/chapters/fs.html
index 0cf20cd..4002736 100644
--- a/chapters/fs.html
+++ b/chapters/fs.html
@@ -1,10 +1,10 @@
 

File System

-

To work with the filesystem, node provides the 'fs' module. The commands follow the POSIX operations, with most methods supporting an asynchronous and synchronous method call. We will look at how to use both and then establish which is the better option.

+

To work with the filesystem, node provides the "fs" module. The commands emulate the POSIX operations, and most methods work synchronously or asynchronously. We will look at how to use both, then establish which is the better option.

Working with the filesystem

-

Lets start with a basic example of working with the filesystem, this example creates a directory, it then creates a file in it. Once the file has been created the contents of the file are written to console:

+

Lets start with a basic example of working with the filesystem. This example creates a directory, creates a file inside it, then writes the contents of the file to console:

var fs = require('fs');
 
@@ -23,7 +23,7 @@ 

Working with the filesystem

});
-

As evident in the example above, each callback is placed in the previous callback - this is what is referred to as chainable callbacks. When using asynchronous methods this pattern should be used, as there is no guarantee that the operations will be completed in the order that they are created. This could lead to unpredictable behavior.

+

As evident in the example above, each callback is placed in the previous callback — these are referred to as chainable callbacks. This pattern should be followed when using asynchronous methods, as there's no guarantee that the operations will be completed in the order they're created. This could lead to unpredictable behavior.

The example can be rewritten to use a synchronous approach:

@@ -34,12 +34,11 @@

Working with the filesystem

console.log(data);
-

It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections and other events.

+

It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections or other events.

File information

-

The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we - are working with. In this example we are getting all the file objects in a directory and displaying whether they are a file or a +

The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we're working with. In this example, we're getting all the file objects in a directory and displaying whether they're a file or a directory object.

var fs = require('fs');
@@ -65,7 +64,7 @@ 

File information

Watching files

-

The fs.watchfile monitors a file and will fire the event whenever the file is changed.

+

The fs.watchfile method monitors a file and fires an event whenever the file is changed.

var fs = require('fs');
 
@@ -81,11 +80,11 @@ 

Watching files

});
-

A file can also be unwatched using the fs.unwatchFile method call. This is used once monitoring of a file is no longer required.

+

A file can also be unwatched using the fs.unwatchFile method call. This should be used once a file no longer needs to be monitored.

Nodejs Docs for further reading

-

The node api docs are very detailed and list all the possible filesystem commands +

The node API docs are very detailed and list all the possible filesystem commands available when working with Nodejs.

diff --git a/chapters/fs.md b/chapters/fs.md index 70daa07..4ec4a51 100644 --- a/chapters/fs.md +++ b/chapters/fs.md @@ -1,11 +1,11 @@ # File System - To work with the filesystem, node provides the 'fs' module. The commands follow the POSIX operations, with most methods supporting an asynchronous and synchronous method call. We will look at how to use both and then establish which is the better option. + To work with the filesystem, node provides the "fs" module. The commands emulate the POSIX operations, and most methods work synchronously or asynchronously. We will look at how to use both, then establish which is the better option. ## Working with the filesystem - Lets start with a basic example of working with the filesystem, this example creates a directory, it then creates a file in it. Once the file has been created the contents of the file are written to console: + Lets start with a basic example of working with the filesystem. This example creates a directory, creates a file inside it, then writes the contents of the file to console: var fs = require('fs'); @@ -23,7 +23,7 @@ }); }); - As evident in the example above, each callback is placed in the previous callback - this is what is referred to as chainable callbacks. When using asynchronous methods this pattern should be used, as there is no guarantee that the operations will be completed in the order that they are created. This could lead to unpredictable behavior. + As evident in the example above, each callback is placed in the previous callback — these are referred to as chainable callbacks. This pattern should be followed when using asynchronous methods, as there's no guarantee that the operations will be completed in the order they're created. This could lead to unpredictable behavior. The example can be rewritten to use a synchronous approach: @@ -33,12 +33,11 @@ console.log('file created with contents:'); console.log(data); - It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections and other events. + It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections or other events. ## File information - The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we - are working with. In this example we are getting all the file objects in a directory and displaying whether they are a file or a + The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we're working with. In this example, we're getting all the file objects in a directory and displaying whether they're a file or a directory object. var fs = require('fs'); @@ -64,7 +63,7 @@ ## Watching files - The fs.watchfile monitors a file and will fire the event whenever the file is changed. + The fs.watchfile method monitors a file and fires an event whenever the file is changed. var fs = require('fs'); @@ -79,18 +78,9 @@ console.log("file write complete"); }); - A file can also be unwatched using the fs.unwatchFile method call. This is used once monitoring of a file is no longer required. - + A file can also be unwatched using the fs.unwatchFile method call. This should be used once a file no longer needs to be monitored. ## Nodejs Docs for further reading - The node api [docs](http://nodejs.org/api.html#file-system-106) are very detailed and list all the possible filesystem commands + The node API [docs](http://nodejs.org/api.html#file-system-106) are very detailed and list all the possible filesystem commands available when working with Nodejs. - - - - - - - - diff --git a/chapters/globals.html b/chapters/globals.html index 420ef58..e344b86 100644 --- a/chapters/globals.html +++ b/chapters/globals.html @@ -1,14 +1,14 @@

Globals

-

As we have learnt node's module system discourages the use of globals, however node provides a few important globals for use to utilize. The first and most important is the process global which exposes process manipulation such as signalling, exiting, the process id (pid), and more. Other globals help drive to be similar to other familiar JavaScript environments such as the browser, by providing a console object.

+

As we have learnt, node's module system discourages the use of globals; however node provides a few important globals for use to utilize. The first and most important is the process global, which exposes process manipulation such as signalling, exiting, the process id (pid), and more. Other globals, such as the console object, are provided to those used to writing JavaScript for web browsers.

console

-

The console object contains several methods which are used to output information to stdout or stderr. Let's take a look at what each method does.

+

The console object contains several methods which are used to output information to stdout or stderr. Let's take a look at what each method does:

console.log()

-

The most frequently used console method is console.log() simply writing to stdout with a line feed (\n). Currently aliased as console.info().

+

The most frequently used console method is console.log(), which simply writes to stdout and appends a line feed (\n). Currently aliased as console.info().

console.log('wahoo');
 // => wahoo
@@ -42,24 +42,24 @@ 

console.assert()

process

-

The process object is plastered with goodies, first we will take a look -at some properties that provide information about the node process itself.

+

The process object is plastered with goodies. First we will take a look +at some properties that provide information about the node process itself:

process.version

-

The version property contains the node version string, for example "v0.1.103".

+

The node version string, for example "v0.1.103".

process.installPrefix

-

Exposes the installation prefix, in my case "/usr/local", as node's binary was installed to "/usr/local/bin/node".

+

The installation prefix. In my case "/usr/local", as node's binary was installed to "/usr/local/bin/node".

process.execPath

-

Path to the executable itself "/usr/local/bin/node".

+

The path to the executable itself "/usr/local/bin/node".

process.platform

-

Exposes a string indicating the platform you are running on, for example "darwin".

+

The platform you are running on. For example, "darwin".

process.pid

@@ -67,7 +67,7 @@

process.pid

process.cwd()

-

Returns the current working directory, for example:

+

Returns the current working directory. For example:

cd ~ && node
 node> process.cwd()
@@ -95,11 +95,11 @@ 

process.getgid()

process.setgid()

-

Similar to process.setuid() however operates on the group, also accepting a numerical value or string representation. For example process.setgid(20) or process.setgid('www').

+

Similar to process.setuid() however operates on the group, also accepting a numerical value or string representation. For example, process.setgid(20) or process.setgid('www').

process.env

-

An object containing the user's environment variables, for example:

+

An object containing the user's environment variables. For example:

{ PATH: '/Users/tj/.gem/ruby/1.8/bin:/Users/tj/.nvm/current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin'
 , PWD: '/Users/tj/ebooks/masteringnode'
@@ -118,7 +118,7 @@ 

process.argv

When executing a file with the node executable process.argv provides access to the argument vector, the first value being the node executable, second being the filename, and remaining values being the arguments passed.

-

For example our source file ./src/process/misc.js can be executed by running:

+

For example, our source file ./src/process/misc.js can be executed by running:

$ node src/process/misc.js foo bar baz
 
@@ -135,11 +135,11 @@

process.argv

process.exit()

-

The process.exit() method is synonymous with the C function exit(), in which a exit code > 0 is passed indicating failure, or 0 to indicate success. When invoked the exit event is emitted, allowing a short time for arbitrary processing to occur before process.reallyExit() is called with the given status code.

+

The process.exit() method is synonymous with the C function exit(), in which an exit code > 0 is passed to indicate failure, or 0 is passed to indicate success. When invoked, the exit event is emitted, allowing a short time for arbitrary processing to occur before process.reallyExit() is called with the given status code.

process.on()

-

The process itself is an EventEmitter, allowing you to do things like listen for uncaught exceptions, via the uncaughtException event:

+

The process itself is an EventEmitter, allowing you to do things like listen for uncaught exceptions via the uncaughtException event:

process.on('uncaughtException', function(err){
     console.log('got an error: %s', err.message);
@@ -153,7 +153,7 @@ 

process.on()

process.kill()

-

process.kill() method sends the signal passed to the given pid, defaulting to SIGINT. In our example below we send the SIGTERM signal to the same node process to illustrate signal trapping, after which we output "terminating" and exit. Note that our second timeout of 1000 milliseconds is never reached.

+

process.kill() method sends the signal passed to the given pid, defaulting to SIGINT. In the example below, we send the SIGTERM signal to the same node process to illustrate signal trapping, after which we output "terminating" and exit. Note that the second timeout of 1000 milliseconds is never reached.

process.on('SIGTERM', function(){
     console.log('terminating');
@@ -172,7 +172,7 @@ 

process.kill()

errno

-

The process object is host of the error numbers, these reference what you would find in C-land, for example process.EPERM represents a permission based error, while process.ENOENT represents a missing file or directory. Typically these are used within bindings to bridge the gap between C++ and JavaScript, however useful for handling exceptions as well:

+

The process object is host of the error numbers, which reference what you would find in C-land. For example, process.EPERM represents a permission based error, while process.ENOENT represents a missing file or directory. Typically these are used within bindings to bridge the gap between C++ and JavaScript, but they're useful for handling exceptions as well:

if (err.errno === process.ENOENT) {
     // Display a 404 "Not Found" page
diff --git a/chapters/globals.md b/chapters/globals.md
index a700986..c069f87 100644
--- a/chapters/globals.md
+++ b/chapters/globals.md
@@ -1,15 +1,15 @@
 
 # Globals
 
- As we have learnt node's module system discourages the use of globals, however node provides a few important globals for use to utilize. The first and most important is the `process` global which exposes process manipulation such as signalling, exiting, the process id (pid), and more. Other globals help drive to be similar to other familiar JavaScript environments such as the browser, by providing a `console` object.
+ As we have learnt, node's module system discourages the use of globals; however node provides a few important globals for use to utilize. The first and most important is the `process` global, which exposes process manipulation such as signalling, exiting, the process id (pid), and more. Other globals, such as the `console` object, are provided to those used to writing JavaScript for web browsers.
 
 ## console
 
-The `console` object contains several methods which are used to output information to _stdout_ or _stderr_. Let's take a look at what each method does.
+The `console` object contains several methods which are used to output information to _stdout_ or _stderr_. Let's take a look at what each method does:
 
 ### console.log()
 
-The most frequently used console method is `console.log()` simply writing to _stdout_ with a line feed (`\n`). Currently aliased as `console.info()`.
+The most frequently used console method is `console.log()`, which simply writes to _stdout_ and appends a line feed (`\n`). Currently aliased as `console.info()`.
 
     console.log('wahoo');
 	// => wahoo
@@ -39,24 +39,24 @@ Asserts that the given expression is truthy, or throws an exception.
 
 ## process
 
-The `process` object is plastered with goodies, first we will take a look
-at some properties that provide information about the node process itself.
+The `process` object is plastered with goodies. First we will take a look
+at some properties that provide information about the node process itself:
 
 ### process.version
 
-The version property contains the node version string, for example "v0.1.103".
+The node version string, for example "v0.1.103".
 
 ### process.installPrefix
 
-Exposes the installation prefix, in my case "_/usr/local_", as node's binary was installed to "_/usr/local/bin/node_".
+The installation prefix. In my case "_/usr/local_", as node's binary was installed to "_/usr/local/bin/node_".
 
 ### process.execPath
 
-Path to the executable itself "_/usr/local/bin/node_".
+The path to the executable itself "_/usr/local/bin/node_".
 
 ### process.platform
 
-Exposes a string indicating the platform you are running on, for example "darwin".
+The platform you are running on. For example, "darwin".
 
 ### process.pid
 
@@ -64,7 +64,7 @@ The process id.
 
 ### process.cwd()
 
-Returns the current working directory, for example:
+Returns the current working directory. For example:
 
     cd ~ && node
     node> process.cwd()
@@ -90,11 +90,11 @@ Returns the numerical group id of the running process.
 
 ### process.setgid()
 
-Similar to `process.setuid()` however operates on the group, also accepting a numerical value or string representation. For example `process.setgid(20)` or `process.setgid('www')`.
+Similar to `process.setuid()` however operates on the group, also accepting a numerical value or string representation. For example, `process.setgid(20)` or `process.setgid('www')`.
 
 ### process.env
 
-An object containing the user's environment variables, for example:
+An object containing the user's environment variables. For example:
 
     { PATH: '/Users/tj/.gem/ruby/1.8/bin:/Users/tj/.nvm/current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin'
 	, PWD: '/Users/tj/ebooks/masteringnode'
@@ -112,7 +112,7 @@ An object containing the user's environment variables, for example:
 
 When executing a file with the `node` executable `process.argv` provides access to the argument vector, the first value being the node executable, second being the filename, and remaining values being the arguments passed.
 
-For example our source file _./src/process/misc.js_ can be executed by running:
+For example, our source file _./src/process/misc.js_ can be executed by running:
 
     $ node src/process/misc.js foo bar baz
 
@@ -127,11 +127,11 @@ in which we call `console.dir(process.argv)`, outputting the following:
 
 ### process.exit()
 
-The `process.exit()` method is synonymous with the C function `exit()`, in which a exit code > 0 is passed indicating failure, or 0 to indicate success. When invoked the _exit_ event is emitted, allowing a short time for arbitrary processing to occur before `process.reallyExit()` is called with the given status code.
+The `process.exit()` method is synonymous with the C function `exit()`, in which an exit code > 0 is passed to indicate failure, or 0 is passed to indicate success. When invoked, the _exit_ event is emitted, allowing a short time for arbitrary processing to occur before `process.reallyExit()` is called with the given status code.
 
 ### process.on()
 
-The process itself is an `EventEmitter`, allowing you to do things like listen for uncaught exceptions, via the _uncaughtException_ event:
+The process itself is an `EventEmitter`, allowing you to do things like listen for uncaught exceptions via the _uncaughtException_ event:
 
 	process.on('uncaughtException', function(err){
 	    console.log('got an error: %s', err.message);
@@ -144,7 +144,7 @@ The process itself is an `EventEmitter`, allowing you to do things like listen f
 
 ### process.kill()
 
-`process.kill()` method sends the signal passed to the given _pid_, defaulting to **SIGINT**. In our example below we send the **SIGTERM** signal to the same node process to illustrate signal trapping, after which we output "terminating" and exit. Note that our second timeout of 1000 milliseconds is never reached.
+`process.kill()` method sends the signal passed to the given _pid_, defaulting to **SIGINT**. In the example below, we send the **SIGTERM** signal to the same node process to illustrate signal trapping, after which we output "terminating" and exit. Note that the second timeout of 1000 milliseconds is never reached.
 
 	process.on('SIGTERM', function(){
 	    console.log('terminating');
@@ -162,7 +162,7 @@ The process itself is an `EventEmitter`, allowing you to do things like listen f
 
 ### errno
 
-The `process` object is host of the error numbers, these reference what you would find in C-land, for example `process.EPERM` represents a permission based error, while `process.ENOENT` represents a missing file or directory. Typically these are used within bindings to bridge the gap between C++ and JavaScript, however useful for handling exceptions as well:
+The `process` object is host of the error numbers, which  reference what you would find in C-land. For example, `process.EPERM` represents a permission based error, while `process.ENOENT` represents a missing file or directory. Typically these are used within bindings to bridge the gap between C++ and JavaScript, but they're useful for handling exceptions as well:
 
     if (err.errno === process.ENOENT) {
 		// Display a 404 "Not Found" page
diff --git a/chapters/modules.html b/chapters/modules.html
index cf78503..4d2a36e 100644
--- a/chapters/modules.html
+++ b/chapters/modules.html
@@ -187,12 +187,12 @@ 

Registering Module Compilers

};
-

Next we have to "register" the extension to assign out compiler. As previously mentioned our compiler lives at ./compiler/extended.js so we are requiring it in, and passing the compile() method to require.registerExtension() which simply expects a function accepting a string, and returning a string of JavaScript.

+

Next we have to "register" the extension to assign our compiler. As previously mentioned, our compiler lives at ./compiler/extended.js; so we are requiring it, passing the compile() method to require.registerExtension() (which simply expects a function accepting a string), and returning a string of JavaScript.

require.registerExtension('.ejs', require('./compiler/extended').compile);
 
-

Now when we require our example, the ".ejs" extension is detected, and will pass the contents through our compiler, and everything works as expected.

+

Now when we require our example, the ".ejs" extension is detected, and will pass the contents through our compiler.

var example = require('./compiler/example');
 console.dir(example)
diff --git a/chapters/modules.md b/chapters/modules.md
index 33d7925..0b89890 100644
--- a/chapters/modules.md
+++ b/chapters/modules.md
@@ -164,11 +164,11 @@ First let's create the module that will actually be doing the ejs to JavaScript
             .replace(/::/g, 'exports.');
     };
 
-Next we have to "register" the extension to assign out compiler. As previously mentioned our compiler lives at _./compiler/extended.js_ so we are requiring it in, and passing the `compile()` method to `require.registerExtension()` which simply expects a function accepting a string, and returning a string of JavaScript.
+Next we have to "register" the extension to assign our compiler. As previously mentioned, our compiler lives at _./compiler/extended.js_; so we are requiring it, passing the `compile()` method to `require.registerExtension()` (which simply expects a function accepting a string), and returning a string of JavaScript.
 
     require.registerExtension('.ejs', require('./compiler/extended').compile);
 
-Now when we require our example, the ".ejs" extension is detected, and will pass the contents through our compiler, and everything works as expected.
+Now when we require our example, the ".ejs" extension is detected, and will pass the contents through our compiler.
 
     var example = require('./compiler/example');
     console.dir(example)
diff --git a/chapters/streams.html b/chapters/streams.html
index 173708b..ee585f3 100644
--- a/chapters/streams.html
+++ b/chapters/streams.html
@@ -1,6 +1,6 @@
 

Streams

-

Streams are an important concept in node. The stream api is a unified way to handle stream-like data, for example data can be streamed to a file, streamed to a socket to respond to an HTTP request, or a stream can be read-only such as reading from stdin. However since we will be touching on stream specifics in later chapters, for now we will concentrate on the api.

+

Streams are an important concept in node. The stream API is a unified way to handle stream-like data. For example, data can be streamed to a file, streamed to a socket to respond to an HTTP request, or streamed from a read-only source such as stdin. For now, we'll concentrate on the API, leaving stream specifics to later chapters.

Readable Streams

@@ -11,8 +11,7 @@

Readable Streams

});
-

As we know, we can call toString() a buffer to return a string representation of the binary data, however in the case of streams if desired we may call setEncoding() on the stream, -after which the data event will emit strings.

+

As we know, we can call toString() on a buffer to return a string representation of the binary data. Likewise, we can call setEncoding() on a stream, after which the data event will emit strings.

req.setEncoding('utf8');
 req.on('data', function(str){
@@ -20,7 +19,7 @@ 

Readable Streams

});
-

Another import event is the end event, which represents the ending of data events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we POST "hello world", our response will be "hello world".

+

Another important event is end, which represents the ending of data events. For example, here's an HTTP echo server, which simply "pumps" the request body data through to the response. So if we POST "hello world", our response will be "hello world".

var http = require('http');
 
@@ -35,7 +34,7 @@ 

Readable Streams

}).listen(3000);
-

The sys module actually has a function designed specifically for this "pumping" action, aptly named sys.pump(), which accepts a read stream as the first argument, and write stream as the second.

+

The sys module actually has a function designed specifically for this "pumping" action, aptly named sys.pump(). It accepts a read stream as the first argument, and write stream as the second.

var http = require('http'),
     sys = require('sys');
diff --git a/chapters/streams.md b/chapters/streams.md
index 238311d..2a1e73a 100644
--- a/chapters/streams.md
+++ b/chapters/streams.md
@@ -1,7 +1,7 @@
 
 # Streams
 
- Streams are an important concept in node. The stream api is a unified way to handle stream-like data, for example data can be streamed to a file, streamed to a socket to respond to an HTTP request, or a stream can be read-only such as reading from _stdin_. However since we will be touching on stream specifics in later chapters, for now we will concentrate on the api.
+ Streams are an important concept in node. The stream API is a unified way to handle stream-like data. For example, data can be streamed to a file, streamed to a socket to respond to an HTTP request, or streamed from a read-only source such as _stdin_. For now, we'll concentrate on the API, leaving stream specifics to later chapters.
  
 ## Readable Streams
 
@@ -11,15 +11,14 @@
         // Do something with the Buffer
     });
 
-As we know, we can call `toString()` a buffer to return a string representation of the binary data, however in the case of streams if desired we may call `setEncoding()` on the stream,
-after which the _data_ event will emit strings.
+As we know, we can call `toString()` on a buffer to return a string representation of the binary data. Likewise, we can call `setEncoding()` on a stream, after which the _data_ event will emit strings.
 
     req.setEncoding('utf8');
     req.on('data', function(str){
         // Do something with the String
     });
 
-Another import event is the _end_ event, which represents the ending of _data_ events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we **POST** "hello world", our response will be "hello world".
+Another important event is  _end_, which represents the ending of _data_ events. For example, here's an HTTP echo server, which simply "pumps" the request body data through to the response. So if we POST "hello world", our response will be "hello world".
 
     var http = require('http');
     
@@ -33,7 +32,7 @@ Another import event is the _end_ event, which represents the ending of _data_ e
         });
     }).listen(3000);
 
-The _sys_ module actually has a function designed specifically for this "pumping" action, aptly named `sys.pump()`, which accepts a read stream as the first argument, and write stream as the second.
+The _sys_ module actually has a function designed specifically for this "pumping" action, aptly named `sys.pump()`. It accepts a read stream as the first argument, and write stream as the second.
 
     var http = require('http'),
         sys = require('sys');