100% found this document useful (4 votes)
76 views

Node Js 8 The Right Way Practical Server Side JavaScript That Scales 1st Edition Jim Wilson All Chapter Instant Download

That

Uploaded by

toyongmta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
76 views

Node Js 8 The Right Way Practical Server Side JavaScript That Scales 1st Edition Jim Wilson All Chapter Instant Download

That

Uploaded by

toyongmta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Download the full version of the textbook now at textbookfull.

com

Node js 8 the Right Way Practical Server Side


JavaScript That Scales 1st Edition Jim Wilson

https://textbookfull.com/product/node-js-8-the-
right-way-practical-server-side-javascript-that-
scales-1st-edition-jim-wilson/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Node js web development server side development with Node


10 made easy Fourth Edition. Edition David Herron

https://textbookfull.com/product/node-js-web-development-server-side-
development-with-node-10-made-easy-fourth-edition-edition-david-
herron/
textbookfull.com

Full Stack JavaScript Learn Backbone js Node js and


MongoDB Mardan Azat

https://textbookfull.com/product/full-stack-javascript-learn-backbone-
js-node-js-and-mongodb-mardan-azat/

textbookfull.com

Node js Design Patterns Master best practices to build


modular and scalable server side web applications 2nd
Edition Casciaro
https://textbookfull.com/product/node-js-design-patterns-master-best-
practices-to-build-modular-and-scalable-server-side-web-
applications-2nd-edition-casciaro/
textbookfull.com

The Abundance Code How To Bust The 7 Money Myths For A


Rich Life Now 1st Edition Julie Ann Cairns

https://textbookfull.com/product/the-abundance-code-how-to-bust-
the-7-money-myths-for-a-rich-life-now-1st-edition-julie-ann-cairns/

textbookfull.com
Biomaterials Nanoarchitectonics 1st Edition Ebara

https://textbookfull.com/product/biomaterials-nanoarchitectonics-1st-
edition-ebara/

textbookfull.com

Microsoft 365 Compliance: A Practical Guide to Managing


Risk Toelle

https://textbookfull.com/product/microsoft-365-compliance-a-practical-
guide-to-managing-risk-toelle/

textbookfull.com

Biofuels for a More Sustainable Future: Life Cycle


Sustainability Assessment, Multi-Criteria Decision Making
1st Edition Alessandro Manzardo
https://textbookfull.com/product/biofuels-for-a-more-sustainable-
future-life-cycle-sustainability-assessment-multi-criteria-decision-
making-1st-edition-alessandro-manzardo/
textbookfull.com

A First Course in Enumerative Combinatorics 1st Edition


Carl G. Wagner

https://textbookfull.com/product/a-first-course-in-enumerative-
combinatorics-1st-edition-carl-g-wagner/

textbookfull.com

Wittgenstein s Folly Philosophy Psychoanalysis and


Language Games 2nd Edition Davoine

https://textbookfull.com/product/wittgenstein-s-folly-philosophy-
psychoanalysis-and-language-games-2nd-edition-davoine/

textbookfull.com
Foundations for Moral Relativism Velleman

https://textbookfull.com/product/foundations-for-moral-relativism-
velleman/

textbookfull.com
Node.js 8 the Right Way
Practical, Server-Side JavaScript That
Scales
by Jim R. Wilson

Version: P1.0 (January 2018)


Copyright © 2018 The Pragmatic Programmers, LLC. This book is licensed to the
individual who purchased it. We don't copy-protect it because that would limit your
ability to use it for your own purposes. Please don't break this trust—you can use this
across all of your devices but please do not share this copy with other members of your
team, with friends, or via file sharing services. Thanks.

Many of the designations used by manufacturers and sellers to distinguish their


products are claimed as trademarks. Where those designations appear in this book, and
The Pragmatic Programmers, LLC was aware of a trademark claim, the designations
have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit,
The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the
linking g device are trademarks of The Pragmatic Programmers, LLC.

Every precaution was taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.

About the Pragmatic Bookshelf


The Pragmatic Bookshelf is an agile publishing company. We’re here because we want
to improve the lives of developers. We do this by creating timely, practical titles, written
by programmers for programmers.

Our Pragmatic courses, workshops, and other products can help you and your team
create better software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at http://pragprog.com.

Our ebooks do not contain any Digital Restrictions Management, and have always been
DRM-free. We pioneered the beta book concept, where you can purchase and read a
book while it’s still being written, and provide feedback to the author to help make a
better book for everyone. Free resources for all purchasers include source code
downloads (if applicable), errata and discussion forums, all available on the book's
home page at pragprog.com. We’re here to make your life easier.

New Book Announcements


Want to keep up on our latest titles and announcements, and occasional special offers?
Just create an account on pragprog.com (an email address and a password is all it
takes) and select the checkbox to receive newsletters. You can also follow us on twitter
as @pragprog.

About Ebook Formats


If you buy directly from pragprog.com, you get ebooks in all available formats for one
price. You can synch your ebooks amongst all your devices (including iPhone/iPad,
Android, laptops, etc.) via Dropbox. You get free updates for the life of the edition. And,
of course, you can always come back and re-download your books when needed.
Ebooks bought from the Amazon Kindle store are subject to Amazon's polices.
Limitations in Amazon's file format may cause ebooks to display differently on different
devices. For more information, please see our FAQ at pragprog.com/frequently-asked-
questions/ebooks. To learn more about this book and access the free resources, go to
https://pragprog.com/book/jwnode2, the book's homepage.

Thanks for your continued support,


Andy Hunt
The Pragmatic Programmers
The team that produced this book includes: Andy Hunt (Publisher),
Janet Furlow (VP of Operations), Brian MacDonald (Managing Editor),
Jacquelyn Carter (Supervising Editor), Candace Cunningham (Copy Editor),
Potomac Indexing, LLC (Indexing), Gilson Graphics (Layout)

For customer support, please contact support@pragprog.com.

For international rights, please contact rights@pragprog.com.


Table of Contents

Acknowledgments

Preface
Why Node.js the Right Way?
What’s in This Book
What This Book Is Not
Code Examples and Conventions
Online Resources

Part I. Getting Up to Speed on


Node.js 8

1. Getting Started
Thinking Beyond the web
Node.js’s Niche
How Node.js Applications Work
Aspects of Node.js Development
Installing Node.js

2. Wrangling the File System


Programming for the Node.js Event Loop
Spawning a Child Process
Capturing Data from an EventEmitter
Reading and Writing Files Asynchronously
The Two Phases of a Node.js Program
Wrapping Up

3. Networking with Sockets


Listening for Socket Connections
Implementing a Messaging Protocol
Creating Socket Client Connections
Testing Network Application Functionality
Extending Core Classes in Custom Modules
Developing Unit Tests with Mocha
Wrapping Up

4. Connecting Robust Microservices


Installing ØMQ
Publishing and Subscribing to Messages
Responding to Requests
Routing and Dealing Messages
Clustering Node.js Processes
Pushing and Pulling Messages
Wrapping Up
Part II. Working with Data

5. Transforming Data and Testing


Continuously
Procuring External Data
Behavior-Driven Development with Mocha and Chai
Extracting Data from XML with Cheerio
Processing Data Files Sequentially
Debugging Tests with Chrome DevTools
Wrapping Up

6. Commanding Databases
Introducing Elasticsearch
Creating a Command-Line Program in Node.js
with Commander
Using request to Fetch JSON over HTTP
Shaping JSON with jq
Inserting Elasticsearch Documents in Bulk
Implementing an Elasticsearch Query Command
Wrapping Up

Part III. Creating an Application


from the Ground Up
7. Developing RESTful Web Services
Advantages of Express
Serving APIs with Express
Writing Modular Express Services
Keeping Services Running with nodemon
Adding Search APIs
Simplifying Code Flows with Promises
Manipulating Documents RESTfully
Emulating Synchronous Style with async and await
Providing an Async Handler Function to Express
Wrapping Up

8. Creating a Beautiful User Experience


Getting Started with webpack
Generating Your First webpack Bundle
Sprucing Up Your UI with Bootstrap
Bringing in Bootstrap JavaScript and jQuery
Transpiling with TypeScript
Templating HTML with Handlebars
Implementing hashChange Navigation
Listing Objects in a View
Saving Data with a Form
Wrapping Up

9. Fortifying Your Application


Setting Up the Initial Project
Managing User Sessions in Express
Adding Authentication UI Elements
Setting Up Passport
Authenticating with Facebook, Twitter, and Google
Composing an Express Router
Bringing in the Book Bundle UI
Serving in Production
Wrapping Up

10. BONUS: Developing Flows with Node-RED


Setting Up Node-RED
Securing Node-RED
Developing a Node-RED Flow
Creating HTTP APIs with Node-RED
Handling Errors in Node-RED Flows
Wrapping Up

A1. Setting Up Angular

A2. Setting Up React

Copyright © 2018, The Pragmatic Bookshelf.


Early praise for Node.js 8 the
Right Way
Node.js 8 the Right Way is an excellent guide for building robust
Node.js applications and making use of the extensive Node.js
ecosystem. Using realistic applications from several different
domains, it gives a highly useful and thorough description of the
process of building, testing, and deploying real-world Node.js
programs.

→ Dan Scales
Principal Engineer, Google Inc.
Without the original Node.js the Right Way, I wouldn’t be where I
am today. This book leapfrogged me from being a casual Node.js
developer to loving the event loop and knowing how to build
effective distributed systems in Node.js. It led me to writing clean,
idiomatic, and highly understandable JavaScript—both in Node.js
and in the browser. This update will do the same for readers.

→ Kyle Kelley
Senior Software Engineer, Netflix
Jim’s update to his engaging, wide-ranging deep dive into how to
solve actual problems using Node.js taught even this old dog some
new tricks. Hats off to Jim for clearly demonstrating how to get the
most out of Node.js.

→ Mark Trostler
Software Engineer, Google Inc.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Jim Wilson shows the correct way, the way that will definitely make
you a better Node.js developer, giving you many techniques,
insights, and—most of all—some really cool stuff. Node.js 8 the Right
Way provides loads of good practices and reveals some of the lower-
level interactions of Node with the system. In a Node.js shop, this
book is a must for seniors’ reference and a must for new hires.

→ Peter Perlepes
Software Engineer, Growth
Acknowledgments
I’m so grateful to have had the opportunity to write this book. And
I’m especially thankful for my editor, Jackie Carter—your thoughtful
feedback made this book what it is today.

Thank you, dear reader, and readers of the Beta releases. Your
errata reports made the book better than it would have otherwise
been.

I’d also sincerely like to thank the whole team at The Pragmatic
Bookshelf. Thanks for your kind patience, and all of your hard work
to polish this book and find all of my mistakes.

I’d like to thank all of my reviewers. Your keen observations have


helped make this book even more technically correct (the best kind
of correct). In no particular order:

Dan Scales Mark Ethan Gary


Trostler Chamberlain
Rick Waldron Nick Capito Peter Hampton

Luca Peter Perlepes Dominic Schulz


Mezzalira
Maricris S. Nonato
And I want to thank my amazing family, too. Dear Ruthy, you are my
inspiration; never stop fighting! Emma and Jimmy, even though
you’re both growing up too fast, I can’t wait to see all the great
things you’ll do.

For anyone I missed, I hope you’ll accept my apologies. Any


omissions were certainly not intentional, and I have nothing but
gratitude for you in my heart.

Copyright © 2018, The Pragmatic Bookshelf.


Preface
In recent years, two big shifts have happened in the practice of
writing software—and Node.js has been at the forefront of both.

First, software is becoming increasingly asynchronous. Whether


you’re waiting on a Big Data job, interacting with end users, steering
a quadcopter, or simply responding to an API call, chances are you’ll
need asynchronous programming techniques.

Second, JavaScript has quietly become the world’s standard code-


execution environment. It’s everywhere: in web browsers, modern
NoSQL databases, DIY robots, and now on the server as well.

Node.js is an integral part of these trends, and it has taken off in a


big way.
Why Node.js the Right Way?
Way back in March of 2010, I gave a lightning talk titled “Full-Stack
JavaScript” at the NoSQL Boston conference. Back then, and even
more so now, I knew that using JavaScript for every layer of the
application stack was not only possible, but was a great way to
reduce software complexity.

When each layer of your stack speaks JavaScript, you sidestep


impedance mismatches and facilitate code reuse. Node.js is an
important piece of the puzzle, filling the middle space between your
front-end user-facing code and your data-storage layer.

The Right Way in this book’s title refers to both the process of
learning Node.js and the practice of writing Node.js code.

Learning Node.js
As with any growing technology, there are plenty of resources
available for learning Node.js. Unfortunately, many of those
resources are narrowly focused on serving up web resources.

The web is great, but it’s not enough, and it’s not the whole story of
Node.js. Node.js is about more than just serving web apps, and this
book treats it that way.

Node.js 8 the Right Way teaches you the concepts you’ll need to be
an effective Node.js programmer, no matter what kinds of programs
you need to write.

Writing Node.js
One thing I love about JavaScript is that there are seven ways to do
anything. There’s breathing room, where developers can explore and
experiment and find better approaches to everything.

The community of Node.js developers, the conventions in Node.js


development, and even the semantics of the JavaScript language
itself are all rapidly evolving. With eyes to the near future, the code
examples and recommendations in this book reflect current best
practices and standards.
What’s in This Book
This book is for intermediate to advanced developers who want to
learn how to write asynchronous JavaScript for the server using
Node.js. Some prior JavaScript experience will definitely help, but
you don’t have to be an expert.

The book proceeds in three parts, outlined here briefly.

Part I: Getting Up To Speed on Node.js 8


Part I is about getting you up to speed on Node.js 8. You’ll write
Node.js programs that use core modules—and a few external
modules as well—to do things like interact with the filesystem, spin
up a cluster of worker processes, and manage network connections.

Getting Started
Chapter 1, ​Getting Started​, introduces the Node.js event loop,
explaining how it empowers Node.js to be highly parallel and single-
threaded at the same time. This chapter also outlines the five
aspects of Node.js development that frame each subsequent chapter
and has some brief instructions on getting Node.js installed on your
machine.

Wrangling the File System


In Chapter 2, ​Wrangling the File System​, you’ll start writing Node.js
programs. If you’ve done any server-side programming in the past,
chances are you’ve had to access a filesystem along the way. We’ll
start in this familiar domain, using Node.js’s filesystem tools to
create asynchronous, nonblocking file utilities. You’ll use Node.js’s
ubiquitous EventEmitter and Stream classes to pipe data, and you’ll
spawn and interact with child processes.
Networking with Sockets
We’ll expand on those concepts while exploring Node.js’s network
I/O capabilities in Chapter 3, ​Networking with Sockets​. You’ll create
TCP servers and client programs to access them. You’ll also develop
a simple JSON-based protocol and a custom class for working with
these messages. To develop unit tests for the code, you’ll use
Mocha, a popular Node.js test harness.

Connecting Robust Microservices


Then, in Chapter 4, ​Connecting Robust Microservices​, we’ll branch
away from the Node.js core and into the realm of third-party
libraries. You’ll use npm to import ØMQ (pronounced “Zero-M-Q”)—a
high-efficiency, low-latency library for developing networked
applications. With ØMQ, you’ll develop programs that communicate
using several important patterns, such as publish/subscribe and
request/reply. You’ll create suites of programs that work together in
concert, and you’ll learn the clustering tools to manage them.

Part II: Working with Data


In Part II, you’ll work with real data and lay the groundwork for an
end-to-end application. This starts with processing data files in a
testable way. You’ll also learn to compose rich command-line utilities
using Node.js and interact with HTTP services.

Transforming Data and Testing Continuously


Chapter 5, ​Transforming Data and Testing Continuously​, kicks off an
ongoing project that spans Part II and Part III. You’ll download the
catalog from Project Gutenberg, an online resource for ebooks in the
public domain. Using a module called Cheerio, you’ll write Node.js
code to parse the data files and extract the important fields. You’ll
use npm, Mocha, and an assertion library called Chai to set up
continuous testing, and you’ll learn to use Chrome DevTools for
interactive debugging.

Commanding Databases
In Chapter 6, ​Commanding Databases​, you’ll insert the extracted
Project Gutenberg catalog into an Elasticsearch index. To get this
done, you’ll write a command-line utility program called esclu using a
Node.js module called Commander. Since Elasticsearch is a RESTful,
JSON-based datastore, you’ll use the Request module to interact
with it. You’ll also learn to use a handy and powerful command-line
tool called jq for manipulating JSON.

Part III: Implementing an Application


Part III is where everything comes together. You’ll develop web
services that mediate between your API users and your back-end
data services. End users don’t interact directly with APIs, though, so
for that you’ll implement a beautiful UI. At the end, you’ll tie it all
together with session management and authentication.

Developing RESTful Web Services


Node.js has fantastic support for writing HTTP servers, and in
Chapter 7, ​Developing RESTful Web Services​, you’ll do exactly that.
You’ll use Express, a popular Node.js web framework for routing
requests. We’ll dive deeper into REST semantics, and you’ll use
Promises and async functions for managing code flows. In addition,
you’ll learn to configure your services using the nconf module, and
keep them running with nodemon.

Creating a Beautiful User Experience


With the web services in place, in Chapter 8, ​Creating a Beautiful
User Experience​, you’ll craft a front end for them. You’ll learn how to
assemble a front-end project using a Node.js-based build tool called
webpack, along with a host of peer-dependency plugins for it. You’ll
transpile your code for consumption by the browser using
TypeScript, a language and transpiler from Microsoft that features
inferred type checking. To make your UI look modern and fabulous,
you’ll bring in Twitter’s Bootstrap styling framework, and implement
templating with Handlebars.

Fortifying Your Application


Chapter 9, ​Fortifying Your Application​, is where everything comes
together. You’ll combine the user experience with the web services
from the previous two chapters for an end-to-end solution. Using
Express middleware, you’ll create authenticated APIs and implement
stateful sessions. You’ll also learn how to use npm’s shrinkwrap option
to insulate yourself from upstream module changes.

Developing Flows with Node-RED


After Part III concludes, there’s a special bonus chapter on Node-
RED. Chapter 10, ​BONUS: Developing Flows with Node-RED​, walks
you through this clever visual editor for designing event-based code
flows. It ships directly with Raspbian, the default operating system
of Raspberry Pi.

Using Node-RED, you can quickly stub out exploratory HTTP APIs. I’ll
show you how!

Appendices on Angular and React


In case you’re interested in using the front-end frameworks Angular
and React, Appendix 1, ​Setting Up Angular​, and Appendix 2, ​Setting
Up React​, show you how to integrate them with webpack and
Express. The appendixes will help you put the pieces in place to start
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
experimenting, but they don’t take the place of a good tutorial on
how to fully develop with them.
What This Book Is Not
Before you commit to reading this book, you should know what it
doesn’t cover.

Everything About Everything


At the time of this writing, npm houses more than 528,000 modules,
with a growth rate of more than 500 new modules per day.[1] Since
the ecosystem and community around Node.js is so large and still
growing so rapidly, this book does not attempt to cover everything.
Instead, this short book teaches you the essentials you need to get
out there and start coding.

In addition to the wealth of Node.js modules available, there’s the


added complexity of working with non-Node.js services and
platforms. Your Node.js code will invariably act as an intermediary
between various systems and users both up and down the stack. To
tell a cohesive story, we’ll naturally only be able to dive deep on a
few of these, but always with an eye to the bigger picture.

MEAN
If you’re looking for an opinionated book that focuses only on a
particular stack like MEAN (Mongo, Express, Angular, and Node.js),
this is not it! Rather than prescribe a particular stack, I’ll teach you
the skills to put together the Node.js code, no matter which back
end you connect to or front end you choose to put on top.

Instead of MongoDB, I’ve selected Elasticsearch to back the projects


in this book because it’s increasingly popular among experienced
Node.js developers, as evidenced by a 2016 survey by RisingStack.[2]
Moreover, with its REST/JSON API, Elasticsearch offers a way to ease
into HTTP services as a consumer before jumping into writing your
own.

This book also shies away from front-end JavaScript frameworks.


The two most popular front-end frameworks at the time of this
writing are React, by Facebook,[3] and Angular, by Google.[4] This
book covers neither of them in detail, by design. They both deserve
more coverage than fits in these pages.

I want you to be the best Node.js coder you can be, whether you
use any particular database or front-end framework.

JavaScript Beginner’s Guide


The JavaScript language is probably the most misunderstood
language today. Although this book does discuss language syntax
from time to time (especially where it’s brand-new), this is not a
beginner’s guide to JavaScript. As a quick quiz, you should be able to
easily read and understand this code:

​ c
​onst​list = [];
​ ​
for​(​let​i = 1; i <= 100; i++) {
​ ​f​(!(i % 15)) {
i
​ list.push(​'FizzBuzz'​);
​ } ​else​​if​(!(i % 5)) {
​ list.push(​'Buzz'​);
​ } ​else​​if​(!(i % 3)) {
​ list.push(​'Fizz'​);
​ } ​else​{
​ list.push(i);
​ }
​ }

You may recognize this as a solution to the classic programming


puzzle called FizzBuzz, made famous by Jeff Atwood in 2007.[5]
Here’s another solution—one that makes gratuitous (and
unnecessary) use of some of the newer JavaScript features.

​ '
​use strict'​
;
​ ​
const​list = [...Array(100).keys()]
​ .map(n => n + 1)
​ .map(n => n % 15 ? n : ​'FizzBuzz'​
)
​ .map(n => isNaN(n) || n % 5 ? n : ​'Buzz'​
)
​ .map(n => isNaN(n) || n % 3 ? n : ​'Fizz'​
);

If you don’t recognize the techniques used in this code, that’s


expected! You’ll learn to use several of them, and many others, in
this book.

A Note to Windows Users


The examples in this book assume you’re using a Unix-like operating
system. We’ll make use of standard input and output streams, and
pipe data between processes. The shell session examples have been
tested with Bash, but other shells may work as well.

If you run Windows, I recommend setting up Cygwin.[6] This will give


you the best shot at running the example code successfully, or you
could run a Linux virtual machine.
Code Examples and Conventions
The code examples in this book contain JavaScript, shell sessions,
and a few HTML/XML excerpts. For the most part, code listings are
provided in full—ready to be run at your leisure.

Samples and snippets are syntax-highlighted according to the rules


of the language. Shell commands are prefixed by $.

When you write Node.js code, you should always handle errors and
exceptions, even if you just rethrow them. You’ll learn how to do this
throughout the book. However, some of the code examples lack
error handling. This is to aid readability and save space, and
sometimes to provide opportunities for reader tasks at the end of
the chapter. In your code, you should always handle your errors.
Random documents with unrelated
content Scribd suggests to you:
Veil-Picard 301
Vovos Elek 290
W
Watteau (Antoine) 314
Wette (Adélaïde) 291
Wolff (Albert) 121
X
Xau (Fernand) 41
Y
Yousouf 3

Imprimerie Générale de Châtillon-s-Seine. — A. Pichat.


Au lecteur.
L'orthographe d'origine a été conservée et n'a pas été
harmonisée, mais les erreurs clairement introduites par le
typographe ont été corrigées. Ces corrections sont soulignées en
pointillés dans le texte. Placez le curseur sur le mot pour voir
l'orthographe originale.
Également, à quelques endroits la ponctuation a été corrigée.
*** END OF THE PROJECT GUTENBERG EBOOK POUSSIÈRES DE
PARIS ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT
GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like