Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some proofreading/changes #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions chapters/buffers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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", however this can be specified by passing a string as the second argument. The ellipsis below for example will be printed to stdout as the '&' character when in "ascii" encoding.

var buf = new Buffer('…');
console.log(buf.toString());
Expand All @@ -23,7 +23,7 @@ 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 method is to pass an array of integers representing the octet stream. The case below is functionally equivalent.

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

Expand All @@ -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 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.

var ellipsis = new Buffer('…', 'utf8');

Expand All @@ -51,7 +51,7 @@ The `.length` property of a buffer instance contains the byte length of the stre

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

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, so 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());
Expand Down
6 changes: 3 additions & 3 deletions chapters/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

## 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;

Expand All @@ -20,7 +20,7 @@ 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 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 using 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_.

Expand Down Expand Up @@ -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. 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_.

var EventEmitter = require('events').EventEmitter;

Expand Down
2 changes: 1 addition & 1 deletion chapters/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

## 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.


Expand Down
10 changes: 5 additions & 5 deletions chapters/globals.md
Original file line number Diff line number Diff line change
@@ -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 us to use. 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.

## 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.

### 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_ with a line feed (`\n`). Currently aliased as `console.info()`.

console.log('wahoo');
// => wahoo
Expand All @@ -19,13 +19,13 @@ The most frequently used console method is `console.log()` simply writing to _st

### console.error()

Identical to `console.log()`, however writes to _stderr_. Aliased as `console.warn()` as well.
Identical to `console.log()`, however it writes to _stderr_. Aliased as `console.warn()` as well.

console.error('database connection failed');

### console.dir()

Utilizes the _sys_ module's `inspect()` method to pretty-print the object to
Uses the _sys_ module's `inspect()` method to pretty-print the object to
_stdout_.

console.dir({ foo: 'bar' });
Expand All @@ -39,7 +39,7 @@ 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
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
Expand Down
4 changes: 2 additions & 2 deletions chapters/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ several 3rd party modules.
module visionmedia jade
module visionmedia ejs

Any machine that can run a shell script can install distributions, and keeps dependencies defined to a single directory structure, making it easy to maintain an deploy. nDistro uses [pre-compiled node binaries](http://github.com/visionmedia/nodes) making them extremely fast to install, and module tarballs which are fetched from [GitHub](http://github.com) via _wget_ or _curl_ (auto detected).
Any machine that can run a shell script can install distributions, and keeps dependencies defined to a single directory structure, making it easy to maintain and deploy. nDistro uses [pre-compiled node binaries](http://github.com/visionmedia/nodes) making them extremely fast to install, and module tarballs which are fetched from [GitHub](http://github.com) via _wget_ or _curl_ (auto detected).

To get started we first need to install nDistro itself, below we _cd_ to our bin directory of choice, _curl_ the shell script, and pipe the response to _sh_ which will install nDistro to the current directory:

Expand Down Expand Up @@ -59,6 +59,6 @@ For those without _git_, or who prefer not to use it, we can also download the s
$ curl -# http://nodejs.org/dist/node-v0.1.99.tar.gz > node.tar.gz
$ tar -zxf node.tar.gz

Now that we have the source on our machine, we can run `./configure` which discovers which libraries are available for node to utilize such as _OpenSSL_ for transport security support, C and C++ compilers, etc. `make` which builds node, and finally `make install` which will install node.
Now that we have the source on our machine, we can run `./configure` which discovers which libraries are available for node to use such as _OpenSSL_ for transport security support, C and C++ compilers, etc. `make` which builds node, and finally `make install` which will install node.

$ ./configure && make && make install
8 changes: 4 additions & 4 deletions chapters/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[CommonJS](http://commonjs.org) is a community driven effort to standardize packaging of JavaScript libraries, known as _modules_. Modules written which comply to this standard provide portability between other compliant frameworks such as narwhal, and in some cases even browsers.

Although this is ideal, in practice modules are often not portable due to relying on apis that are currently only provided by, or are tailored to node specifically. As the framework matures, and additional standards emerge our modules will become more portable.
Although this is ideal, in practice modules are often not portable due to relying on APIs that are currently only provided by, or are tailored to node specifically. As the framework matures, and additional standards emerge our modules will become more portable.

## Creating Modules

Expand Down Expand Up @@ -45,7 +45,7 @@ on the `exports` object like so:
return obj;
};

Next we will look at utilizing out new module in other libraries.
Next we will look at using our new module in other libraries.

## Requiring Modules

Expand Down Expand Up @@ -77,7 +77,7 @@ This technique is usually only helpful when your module has one aspect that it w

exports.Animal = function Animal(){};

which can then be utilized as shown:
which can then be used as shown:

var Animal = require('./animal').Animal;

Expand All @@ -91,7 +91,7 @@ which can now be used without the property:

## Require Paths

We talked about `require.paths`, the `Array` utilized by node's module system in order to discover modules. By default node checks the following directories for modules:
We talked about `require.paths`, the `Array` used by node's module system in order to discover modules. By default node checks the following directories for modules:

- `<node binary>`/../../lib/node
- **$HOME**/.node_libraries
Expand Down
2 changes: 1 addition & 1 deletion chapters/streams.md
Original file line number Diff line number Diff line change
@@ -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 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.

## Readable Streams

Expand Down