Skip to content

Commit a6b4364

Browse files
committed
Improved a few lab wording
1 parent 610ea0e commit a6b4364

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

_posts/2012-11-2-shell.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tags:
77

88
# A Node.js Shell
99

10-
In this lab we'll put together a simple shell. We'll interact with the file system and learn some useful facets of the JavaScript programming language.
10+
In this lab we'll put together a simple shell. We'll interact with the file system and network while learning some useful features of JavaScript.
1111

1212
- [Working with standard input](#working_with_standard_input)
1313
- [Implementing a print working directory command](#implementing_a_print_working_directory_command)
@@ -18,7 +18,7 @@ In this lab we'll put together a simple shell. We'll interact with the file syst
1818

1919
Commands will be provided to our shell through the process' standard input. By default, Node.js does not activate the standard input stream. The first thing we'll do is enable standard input and echo back what we read.
2020

21-
Create a new file called `shell.js` and add the following:
21+
Create a new file called `shell.js` in a brand new directory and add the following:
2222

2323
{% highlight javascript %}
2424
var stdin = process.openStdin();
@@ -28,7 +28,7 @@ stdin.on('data', function (input) {
2828
});
2929
{% endhighlight %}
3030

31-
Before we go any further, let's experiment with what the above code does. Run the file:
31+
Before we go any further, let's experiment with what the above code does. To run the file:
3232

3333
{% highlight bash %}
3434
$ node shell.js
@@ -47,7 +47,7 @@ bar
4747

4848
You can see that we're printing out a `Buffer` object. That's because the `input` variable passed in to our `function (input) { ... }` callback does not contain the string value of your input directly.
4949

50-
It's worth noting that, at this point, the buffer exists completely outside of the JavaScript memory space (the `Buffer` is an object from the C++ Node.js internals). Interacting with this buffer will move data across the native to JavaScript boundary. For example, calling `input.toString()` will create a new JavaScript string containing the entire contents of the `Buffer`. An optional encoding can be specified as the first argument of the `toString` function (for example, `input.toString('utf8')`).
50+
It's worth noting that, at this point, the buffer exists completely outside of the JavaScript memory space (`Buffer` is an object from the C++ Node.js internals). Interacting with this buffer will move data from between the native (C++) and JavaScript boundary. For example, calling `input.toString()` will create a new JavaScript string containing the entire contents of the `Buffer`. An optional encoding can be specified as the first argument of the `toString` function (for example, `input.toString('utf8')`).
5151

5252
Since we're working with relatively short strings, let's go ahead and call `input.toString()` on the Buffer. Here's what your program should look like now:
5353

@@ -61,7 +61,7 @@ stdin.on('data', function (input) {
6161

6262
Now starting up the shell and typing any value will result in the expected output ending with the new line character.
6363

64-
The next step is to parse the input string. The commands in our simple shell will take the form:
64+
The next step is to trim and parse the input string. The commands in our simple shell will take the form:
6565

6666
{% highlight bash %}
6767
command [args...]
@@ -128,7 +128,7 @@ To clarify what's happening above, here's sample output of executing the regular
128128

129129
We are accessing ```matches[1]``` because it's the first group (groups are specified with the parenthesis). If you are unfamiliar with regular expressions, a good source to learn more is at [http://regular-expressions.info](http://www.regular-expressions.info/).
130130

131-
Now, jump back to your terminal and give our shell a try!
131+
Now, jump back to your terminal and give your shell a try!
132132

133133
Start up the shell with the `node` command and execute our one and only command:
134134

@@ -219,9 +219,11 @@ commands['ls'] = function (args) {
219219
};
220220
{% endhighlight %}
221221

222+
In this example we're defining a container object `commands` and assigning anonymous functions to properties on that object. The major difference from before is that the function definitions are not part of the object initializer. There's no difference in behavior between the two approaches.
223+
222224
## Interacting with HTTP: Downloading a File
223225

224-
Similarly to the `fs` module, Node.js also contains a core `http` module which can be used to act as a HTTP client or server. In the next lab you'll be creating a HTTP server, but for now, we'll focus on creating a simple `wget` command to download a file.
226+
Similarly to the `fs` module, Node.js core contains a `http` module which can be used to act as a HTTP client or server. In the next lab you'll be creating a HTTP server, but for now, we'll focus on creating a simple `wget` command to download a file.
225227

226228
Import the `http` module up top next to where you imported `fs`:
227229

_posts/2012-11-6-npm.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ Modules can be installed using the Node.js package manager `npm` to be included
117117
For the next example, let's take a list of numbers and sort and filter them. To do this, we'll include the [underscore.js module](https://npmjs.org/package/underscore). First we need to install underscore by executing the following command from a brand new directory.
118118

119119
{% highlight bash %}
120-
$ npm init
121-
/* fill out the defaults */
120+
$ npm init /* fill out the defaults */
122121
$ npm install underscore --save
123122
{% endhighlight %}
124123

0 commit comments

Comments
 (0)