Skip to content

Commit

Permalink
Chapter 4 cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanRBrown committed Jan 13, 2020
1 parent 28e431d commit 2a1c079
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ The [Chapter 2 Examples](ch02/README.md) demonstrate a simple, minimal web serve
### Chapter 3

The [Chapter 3 Examples](ch03/README.md) demonstrate a simple, minimal web server using Express.

### Chapter 4

The [Chapter 4 Example](ch03/README.md) take the "fortune cookie" functionality deveoped in Chapter 3, and implement it as a Node module.
23 changes: 23 additions & 0 deletions ch04/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Chapter 4 Examples - Web Development with Node and Express, 2nd Edition

## Using Node Modules

This chapter is mostly background information, so there's only one example in this chapter; taking the "fortunte cookie" functionality that was developed in Chapter 3, and placing it in a Node module. See _lib/fortune.js_ and _meadowlark.js_.

### Setup

The example in this chapter has Node module dependencies (`express` and `express-handlebars`). These dependencies are listed in the _package.json_ file. However, when you first clone this repo, you won't have them installed (_package.json_ is simply a manifest). To install them, simply run:

```
npm install
```

### Running

Minimal example; uses Express, but doesn't do very much. To run:

```
node 00-meadowlark
```

Then visit _http://localhost:3000/about_ in your browser.
1 change: 1 addition & 0 deletions ch04/lib/fortune.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fortuneCookies = [
"You will have a pleasant surprise.",
"Whenever possible, keep it simple.",
]

exports.getFortune = () => {
const idx = Math.floor(Math.random()*fortuneCookies.length)
return fortuneCookies[idx]
Expand Down

0 comments on commit 2a1c079

Please sign in to comment.