Learning Nodejs ForNet Developers Harry
Cummings download
https://ebookbell.com/product/learning-nodejs-for-net-developers-
harry-cummings-55921114
Explore and download more ebooks at ebookbell.com
2.
Here are somerecommended products that we believe you will be
interested in. You can click the link to download.
Learning Nodejs For Net Developers Harry Cummings
https://ebookbell.com/product/learning-nodejs-for-net-developers-
harry-cummings-5698934
Learning Nodejs For Mobile Application Development Make Use Of Nodejs
To Learn The Development Of A Simple Yet Scalable Crossplatform Mobile
Application Stefan Buttigieg
https://ebookbell.com/product/learning-nodejs-for-mobile-application-
development-make-use-of-nodejs-to-learn-the-development-of-a-simple-
yet-scalable-crossplatform-mobile-application-stefan-buttigieg-5473944
Machine Learning For Network Traffic And Video Quality Analysis
Develop And Deploy Applications Using Javascript And Nodejs Tulsi
Pawan Fowdur Lavesh Babooram
https://ebookbell.com/product/machine-learning-for-network-traffic-
and-video-quality-analysis-develop-and-deploy-applications-using-
javascript-and-nodejs-tulsi-pawan-fowdur-lavesh-babooram-57865974
Learning Nodejs A Handson Guide To Building Web Applications In
Javascript Marc Wandschneider
https://ebookbell.com/product/learning-nodejs-a-handson-guide-to-
building-web-applications-in-javascript-marc-wandschneider-5474192
3.
Learning Nodejs DevelopmentLearn The Fundamentals Of Nodejs And
Deploy And Test Nodejs Applications On The Web 1st Edition Andrew Mead
https://ebookbell.com/product/learning-nodejs-development-learn-the-
fundamentals-of-nodejs-and-deploy-and-test-nodejs-applications-on-the-
web-1st-edition-andrew-mead-7227756
Learning Nodejs Development Learn The Fundamentals Of Nodejs And
Deploy And Test Nodejs Applications On The Web Andrew Mead
https://ebookbell.com/product/learning-nodejs-development-learn-the-
fundamentals-of-nodejs-and-deploy-and-test-nodejs-applications-on-the-
web-andrew-mead-11083198
Learning Nodejs A Handson Guide To Building Web Applications In
Javascript Marc Wandschneider
https://ebookbell.com/product/learning-nodejs-a-handson-guide-to-
building-web-applications-in-javascript-marc-wandschneider-5412058
Learning Nodejs A Handson Guide To Building Web Applications In
Javascript 2013th Edition Marc Wandschneider
https://ebookbell.com/product/learning-nodejs-a-handson-guide-to-
building-web-applications-in-javascript-2013th-edition-marc-
wandschneider-67713592
Learn Nodejs By Building 6 Projects Build Six Practical And
Instructive Nodejs Projects Solutions
https://ebookbell.com/product/learn-nodejs-by-building-6-projects-
build-six-practical-and-instructive-nodejs-projects-solutions-55918930
Table of Contents
LearningNode.js for .NET Developers
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Why Node.js?
What is Node.js?
Understanding the Node.js execution model
Non-blocking
Event-driven
Single-threaded
Introducing the Node.js ecosystem
Why JavaScript?
A clear canvas
Functional nature
A bright future
When to use Node.js
Writing web applications
Identifying other use cases
Why now?
Summary
2. Getting Started with Node.js
Installing and running Node.js
Choosing an editor
Using an application framework
Getting started with Express
Exploring our Express application
8.
Understanding Express routesand views
Using nodemon for automatic restarts
Creating modular applications with Express
Bootstrapping an Express application
Understanding Express middleware
Implementing error handling
Using Express middleware
Summary
3. A JavaScript Primer
Introducing JavaScript types
JavaScript primitive types
Functional object-oriented programming
Functional programming in JavaScript
Understanding scopes in JavaScript
Strict mode
Object-oriented programming in JavaScript
Programming without classes
Creating objects with the new keyword
Programming with classes
Class-based inheritance
Summary
4. Introducing Node.js Modules
Organizing your codebase
JavaScript module systems
Creating modules in Node.js
Declaring a module with a name and its own scope
Defining functionality provided by the module
Importing a module into another script
Defining a directory-level module
Implementing an Express middleware module
Summary
5. Creating Dynamic Websites
Handling user-submitted data
Communicating via Ajax
Implementing other data operations
Listing data in views
Issuing a delete request from the client
Splitting up Express views using partials
Summary
6. Testing Node.js Applications
Writing a simple test in Node.js
Structuring the codebase for tests
Writing BDD-style tests with Mocha
Resetting state between tests
9.
Using Chai forassertions
Creating test doubles
Creating test doubles using Sinon.JS
Testing an Express application
Simplifying tests using SuperAgent
Full-stack testing with PhantomJS
Summary
7. Setting up an Automated Build
Setting up an integration server
Setting up a public GitHub repository
Building a project on Travis CI
Automating the build process with Gulp
Running tests using Gulp
Checking code style with ESLint
Automatically fixing issues in ESLint
Running ESLint from Gulp
Gathering code coverage statistics
Running integration tests from Gulp
Summary
8. Mastering Asynchronicity
Using the callback pattern for asynchronous code
Exposing the callback pattern
Consuming asynchronous interfaces
Writing cleaner asynchronous code using promises
Implementing promise-based asynchronous code
Consuming the promise pattern
Parallelising operations using promises
Combining asynchronous programming patterns
Summary
9. Persisting Data
Introducing MongoDB
Why choose MongoDB?
Object modeling
JavaScript
Scalability
Getting started with MongoDB
Using the MongoDB shell
Using MongoDB with Express
Persisting objects with Mongoose
Isolating persistence code
Dependency injection in Node.js
Providing dependencies
Running database integration tests on Travis CI
Introducing Redis
10.
Why use Redis?
InstallingRedis
Using Redis as a key-value store
Storing structured data in Redis
Building a user ranking system with Redis
Using Redis from Node.js
Testing with redis-js
Implementing user rankings with Redis
Making use of the users service
A note on security
Summary
10. Creating Real-time Web Apps
Understanding options for real-time communication
Introducing Socket.IO
Implementing a chat room with Socket.IO
Scaling real-time Node.js applications
Using Redis as a backend
Integrating Socket.IO with Express
Directing Socket.IO messages
Testing Socket.IO applications
Organizing Socket.IO applications
Exposing real-time updates to the model
Organizing Socket.IO applications using namespaces
Partitioning Socket.IO clients using rooms
Summary
11. Deploying Node.js Applications
Working with Heroku
Setting up a Heroku account and tooling
Running an application locally with Heroku
Deploying an application to Heroku
Working with Heroku logs, config, and services
Setting up MongoDB
Setting up Redis
Deploying from Travis CI
Setting encrypted Travis CI environment variables
Installing Ruby
Creating an encrypted environment variable
Further resources
Summary
12. Authentication in Node.js
Introducing Passport
Choosing an authentication strategy
Understanding third-party authentication
Using Express sessions
11.
Specifying a sessionsecret
Deciding when the session gets saved
Using alternative session stores
Using session middleware
Implementing social login
Setting up a Twitter application
Configuring Passport
Persisting user data with Redis
Configuring Passport with persistence
Hiding functionality from unauthenticated users
Integration testing with Passport
Allowing users to log out
Adding other login providers
Summary
13. Creating JavaScript Packages
Writing universal modules
Comparing Node.js and RequireJS
Supporting the browser environment
Using AMD modules with RequireJS
Isomorphic JavaScript
Writing npm packages
Defining an npm package
Publishing a package to npm
Running automated clients on the web
Releasing a standalone tool to npm
Using Node.js modules in the browser
Controlling Browserify's output
Summary
14. Node.js and Beyond
Understanding Node.js versioning
A brief history of Node.js
Introducing the Node.js LTS schedule
Understanding ECMAScript versioning
Exploring ECMAScript 2015
Understanding ES2015 modules
Using syntax improvements from ES2015
The for... of loop
The spread operator and rest parameters
Destructuring assignment
Introducing generators
Introducing ECMAScript 2016
Going beyond JavaScript
Exploring compile-to-JavaScript languages
TypeScript
12.
CoffeeScript
And beyond...
Introducing atrue assembly language for the web
Understanding asm.js
Understanding WebAssembly
JavaScript and ASP.NET
Exploring .NET Core
Defining project structure in .NET Core
Managing dependencies in .NET Core
Building web applications in ASP.NET Core
Integration with JavaScript
Server-side JavaScript integration with .NET
Summary
Index
About the Author
HarryCummings has been working in software development for 8 years, and for the past few
years, he has performed the role of technical lead across a variety of projects for varied clients.
He has, in the past, also worked as a developer, project manager, and consultant. This gives him
an excellent all-round view of the role of a technical lead and its relationship with other roles as
well as insight into every stage of project delivery, from initial analysis to long-term maintenance.
Harry has extensive experience in C#/.NET, Java and Scala, and JavaScript/Node.js. He
continues to work directly with these technologies on a regular basis in the teams that he leads.
His broader interests and expertise lie in sharing and nurturing software development best
practices through training and mentoring. He has appeared at conferences such as NDC London
and SDD Conf, speaking about diverse topics, ranging from introductory Node.js through to
automated test strategies and long-term project maintainability.
18.
About the Reviewer
DavidSimons is a London-based software consultant. He is familiar with a wide range of tools,
having helped clients such as the BBC and News International deliver web solutions in a range of
languages, including .NET, Java, and full-stack JavaScript. He shares his insights around these
and his background in statistics research at a range of conferences, including NDC and JSConf.
As of 2016, he works with London-based consultancy GraphAware to advocate and consult on the
use of graph databases in modern applications.
eBooks, discount offers,and more
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files
available? You can upgrade to the eBook version at www.PacktPub.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get in touch with us at
<customercare@packtpub.com> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can search, access, and read Packt's entire library of books.
21.
Why subscribe?
Fully searchableacross every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
22.
Preface
The purpose ofthis book is to help .NET or Java developers make the leap to Node.js. You may
have some web development experience, and perhaps you've written some browser-based
JavaScript in the past. It might not be obvious why anyone would want to take JavaScript out of
the browser and use it for server-side development. However, this is exactly what Node.js does.
What's more, Node.js has been around for long enough now to have matured as a platform, and
has sustained its impressive growth in popularity well beyond any period that could be attributed
to initial hype over a new technology.
The first objective of this book then is to explain why Node.js is a compelling technology that's
worth learning more about. The first few chapters introduce Node.js with this in mind, quickly get
you up and running with Node.js, and provide an important (re) introduction to the JavaScript
language to set you on the right track.
The main part of this book will then take you through a worked example of building up a Node.js
web-application step by step. In the process, we'll illustrate all the important tools and techniques
required for real-world development projects in Node.js. The aim is to make the most of your
existing development expertise to allow you to quickly reach the same level of best practices and
professionalism with Node.js.
The final chapters of the book show how to use Node.js for other purposes outside of web
applications and how to continue learning Node.js and exploring the ecosystem around it. We'll
also see how you can use Node.js alongside .NET and benefit from applying your programming
skills across both technologies.
23.
What this bookcovers
Chapter 1, Why Node.js?, introduces Node.js as a programming platform. It covers the execution
model of Node.js, particularly how it differs from .NET and Java, and the use cases in which
these differences become strengths. This chapter also discusses the suitability of JavaScript as a
development language.
Chapter 2, Getting Started with Node.js, dives straight into creating a Node.js application. In this
chapter, you will install Node.js, choose a code editor, and set up a minimal web application
project. You'll also learn some important command-line tools for working with Node.js.
Chapter 3, A JavaScript Primer, introduces the most important things to know when programming
in JavaScript. It describes the JavaScript type system and its particular flavor of functional
object-oriented programming, including prototype-based inheritance. This chapter also covers a
few key gotchas and JavaScript language quirks.
Chapter 4, Introducing Node.js Modules, explains how to structure JavaScript applications using
modules. It introduces the Node.js module system and shows you how to use this to organise your
application's code.
Chapter 5, Creating Dynamic Websites, expands on the examples from the previous chapter to
build a functioning web application. You'll add a JSON API and dynamic views to your
application and communicate between the client and server using Ajax.
Chapter 6, Testing Node.js Applications, shows you how to write automated tests in JavaScript
and Node.js. It introduces a number of tools and libraries for writing and running tests in
JavaScript, and guides you through writing a variety of unit tests and integration tests for your
application.
Chapter 7, Setting up an Automated Build, covers build automation and continuous integration in
Node.js. You'll set up a CI server and task runner for your application, adding automated tasks to
run tests, execute static analysis, and assess code coverage.
Chapter 8, Mastering Asynchronicity, introduces different patterns for asynchronous
programming in JavaScript. You'll apply these to your own application and make the most of
JavaScript language features and libraries for simplifying asynchronous code.
Chapter 9, Persisting Data, explains persistent data stores that can be used with Node.js. It
introduces MongoDB and Redis, explaining their different data models and their use cases. You'll
integrate both of these data stores with your Node.js application.
Chapter 10, Creating Real-time Web Apps, shows how to implement real-time two-way
communication between the client and the server. You'll use the Socket.IO library to add real-time
functionality into your application. You'll also see how to write tests for this functionality and
24.
how to writescalable real-time applications using Redis as a backend.
Chapter 11, Deploying Node.js Applications, demonstrates how to get a Node.js application onto
the Web. You'll deploy your application to a free cloud-hosting provider. You'll see how to
configure data stores and how to use remote server logs for debugging.
Chapter 12, Authentication in Node.js, covers authentication for Node.js web applications.
You'll implement authentication using third-party providers, integrate this with your application,
and show different content to logged-in and logged-out users.
Chapter 13, Creating JavaScript Packages, explains how to create standalone JavaScript
packages for use by others. You'll see how to write universal JavaScript libraries that can run on
both the client and the server, and how to write a standalone command-line application using
Node.js.
Chapter 14, Node.js and Beyond, puts the content of this book in a wider context. It explains how
Node.js and JavaScript are continuing to evolve, so you can be prepared for and take advantage
of upcoming changes. It covers some alternative programming languages for Node.js and the Web,
and how these relate to JavaScript. It discusses how some of the principles from Node.js can be
applied to .NET programming, and illustrates how these are particularly visible in .NET Core
(the new version of .NET). It also shows how you can use Node.js together with .NET to gain the
best of both worlds.
25.
What you needfor this book
All of the tools and services used in this book are available for free online. Most of the worked
examples require an active web connection at some point. To get started, you need nothing more
than a console, a web browser, and permission to install new software on your machine. To
support developers coming from a .NET background, some of the console listings or example
steps in this book use Windows conventions (for example, backslashes in paths). None of the
examples depend on Windows specifically though. You can work through this book on Windows,
Mac OSX, or Linux.
26.
Who this bookis for
This book is for .NET or Java developers who are interested in learning Node.js. No prior
experience with Node.js is expected. You might have written some client-side JavaScript before,
but this is not required. The main worked example in this book is a Node.js web application. Web
development experience in .NET or Java will be helpful, but it's not necessary to have experience
with any particular application library or framework.
27.
Conventions
In this book,you will find a number of text styles that distinguish between different kinds of
information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames,
dummy URLs, user input, and Twitter handles are shown as follows: "ES2015 introduces the let
keyword for declaring variables."
A block of code is set as follows:
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1>{{ title }}</h1>
<p>Welcome to {{ title }}</p>
</body>
</html>
When we wish to draw your attention to a particular part of a code block, the relevant lines or
items are set in bold:
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express', name: 'World' });
});
Any command-line input or output is written as follows:
> npm install –g nodemon
New terms and important words are shown in bold. Words that you see on the screen, for
example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves
you to the next screen."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
28.
Reader feedback
Feedback fromour readers is always welcome. Let us know what you think about this book—
what you liked or disliked. Reader feedback is important for us as it helps us develop titles that
you will really get the most out of.
To send us general feedback, simply e-mail <feedback@packtpub.com>, and mention the book's
title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing
to a book, see our author guide at www.packtpub.com/authors.
29.
Customer support
Now thatyou are the proud owner of a Packt book, we have a number of things to help you to get
the most from your purchase.
30.
Downloading the examplecode
You can download the example code files for this book from
https://github.com/NodeJsForDevelopers and also from your account at
http://www.packtpub.com. If you purchased this book elsewhere, you can visit
http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.
You can also download the code files by clicking on the Code Files button on the book's webpage
at the Packt Publishing website. This page can be accessed by entering the book's name in the
Search box. Please note that you need to be logged in to your Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest
version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
31.
Downloading the colorimages of this book
We also provide you with a PDF file that has color images of the screenshots/diagrams used in
this book. The color images will help you better understand the changes in the output. You can
download this file from
http://www.packtpub.com/sites/default/files/downloads/LearningNodejsForNETDevelopers_ColorIma
32.
Errata
Although we havetaken every care to ensure the accuracy of our content, mistakes do happen. If
you find a mistake in one of our books—maybe a mistake in the text or the code—we would be
grateful if you could report this to us. By doing so, you can save other readers from frustration and
help us improve subsequent versions of this book. If you find any errata, please report them by
visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata
Submission Form link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added to any list
of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support
and enter the name of the book in the search field. The required information will appear under the
Errata section.
33.
Piracy
Piracy of copyrightedmaterial on the Internet is an ongoing problem across all media. At Packt,
we take the protection of our copyright and licenses very seriously. If you come across any illegal
copies of our works in any form on the Internet, please provide us with the location address or
website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
34.
Questions
If you havea problem with any aspect of this book, you can contact us at
<questions@packtpub.com>, and we will do our best to address the problem.
35.
Chapter 1. WhyNode.js?
Node.js is still relatively new compared to platforms such as .NET and Java, but has become
very popular in a short time, and has even started influencing these platforms. This is thanks to its
distinctive programming model, extensive ecosystem, and powerful tooling.
These factors make Node.js a compelling alternative to other platforms. They can also make it
intimidating. Its distinctive programming model may seem quite alien compared to other
platforms. The sheer range of available libraries and tools can be bewildering.
This book will guide you through Node.js so you can start using it in your applications. It will
help you to understand Node.js, navigate its ecosystem, and leverage your existing development
skills in this new environment.
In this chapter, we will cover the following topics:
Introducing the Node.js platform
Seeing how its execution model works
Exploring the Node.js ecosystem
Looking at JavaScript as a language choice
Considering the range of use cases for Node.js
36.
What is Node.js?
Node.jsconsists of a JavaScript engine together with low-level APIs for core server-side
functionality. The execution engine is the same V8 engine developed for the Chrome web
browser. Node.js takes this engine and embeds it in a standalone application that can run
JavaScript outside the browser.
In Node.js, the standard APIs found in browsers to support client-side web development, such as
the Document Object Model (DOM) and XMLHttpRequest, are not present. Instead, there are
APIs to support general-purpose application development. These core APIs cover low-level
functionality such as the following:
Networking and security
Accessing the file system
Defining and requiring modules
Raising and consuming events
Handling binary data streams
Compression
UTF-8 support
Retrieving basic information about the OS
Managing child processes
Some of these APIs may already be familiar from developing client-side JavaScript. For
example, the Timers API exposes the familiar setTimeout and setInterval functions.
Node.js also provides several tools to help with the development process. These include console
logging, debugging, a Read-Eval-Print Loop (REPL) (or interactive console), and basic
assertions for testing.
37.
Understanding the Node.jsexecution model
The execution model of Node.js follows that of JavaScript in the browser. It is quite different
from that of most general-purpose programming platforms.
Stated formally, Node.js has a single-threaded, non-blocking, event-driven execution model. We
will define each of these terms in this section.
Non-blocking
Put simply, Node.js recognizes that many programmes spend most of their time waiting for other
things to happen, for example, slow I/O operations such as disk access and network requests.
Node.js addresses this by making these operations non-blocking. This means that program
execution can continue while they happen. For example, the filesystem API's stat function for
retrieving statistics about a file may be called as follows:
fs.stat('/hello/world', function (error, stats) {
console.log('File last updated at: ' + stats.mtime);
});
Two arguments are passed to the fs.stat function: the name of the file that we are interested in,
and a callback function. The fs.stat call returns immediately, returning control of execution to
the current thread but not returning a value. If there are further commands following the fs.stat
call, these will then be executed. Otherwise, the thread is released to perform other work. The
callback function is invoked (that is 'called back') only after the runtime has finished
communicating with the filesystem. The result of the filesystem operation is passed into the
callback function.
This non-blocking approach is also called asynchronous programming. Other platforms support
this (for example, C#'s async/await keywords and .NET's Task Parallel Library). However, it is
baked in to Node.js in a way that makes it simple and natural to use. Asynchronous API methods
are all called in the same way as fs.stat. They all take a callback function that gets passed error
and result arguments.
Event-driven
The event-driven nature of Node.js describes how operations are scheduled. In typical
procedural environments, a program has an entry point that executes a set of commands until
completion, or enters a loop and performs some processing on each iteration.
Node.js has a built-in event loop, which isn't exposed to the developer. It is the job of the event
loop to decide which piece of code to execute next. Typically, this will be a callback function that
is ready to run in response to some other event. For example, a filesystem operation may have
completed, a timeout may have expired, or a new network request may have arrived.
This built-in event loop simplifies asynchronous programming by providing a consistent approach
38.
and avoiding theneed for applications to manage their own scheduling.
Single-threaded
The single-threaded nature of Node.js simply means that there is only one thread of execution in
each process. Also, each piece of code is guaranteed to run to completion without being
interrupted by other operations. This greatly simplifies development and makes programs easier
to reason about. It removes the possibility for a range of concurrency issues. For example, it is
not necessary to synchronize/lock access to shared in-process state as it is in Java or .NET. A
process can't deadlock itself or create race conditions within its own code. Single-threaded
programming is only feasible if the thread never gets blocked waiting for long-running work to
complete. Thus, this simplified programming model is made possible by the non-blocking nature
of Node.js.
39.
Introducing the Node.jsecosystem
The built-in Node.js APIs provide a low-level core for creating applications. Applications
typically only use a small number of these APIs directly. They often use third-party library
modules that provide higher-level abstractions for application development.
Node.js has its own package manager, npm. This is similar to .NET's NuGet or the package
management aspects of Java's Maven. Applications specify their dependencies in a simple JSON
file.
The npm registry provides a central repository for packages. This registry has grown rapidly and
is already much larger (in terms of number of available packages) than the corresponding
repositories for other platforms (see http://www.modulecounts.com/). There are hundreds of
thousands of packages available, providing a vast array of functionality.
The npm command line tool can be used to download packages and install new ones. Library
dependencies are installed locally to each application. Some packages provide command-line
tools, which may be installed globally rather than under a specific project.
Many frameworks available on npm are split into a small extensible core and a number of
composable modules. This approach makes it easy to understand the libraries on which your
application depends, avoiding the need to reason about complex heavyweight frameworks.
The consistency of calling non-blocking (asynchronous) API methods in Node.js carries through
to its third-party libraries. This consistency makes it easy to build applications that are
asynchronous throughout.
40.
Why JavaScript?
JavaScript isa language that can seem unintuitive compared to other popular object-oriented
(OO) languages. It also has a number of quirks and flaws that have drawn criticism (and
occasional ridicule). It might then seem a surprising choice of language for a new programming
platform. This section discusses the factors that make JavaScript a more appealing choice.
41.
A clear canvas
Thesize and complexity of JavaScript is part of its appeal. The core language itself, which
doesn't include APIs such as the DOM, is small and simple. This makes it easy for Node.js to
establish its own styles and conventions.
The new APIs provided by Node.js and the consistent approach to asynchronous programming
wouldn't be possible in a more complex language with a larger pre-existing standard class
library.
42.
Functional nature
JavaScript wasfirst built as a programming language for client-side functionality in the browser.
This might not make it an obvious choice for general-purpose programming.
In fact, these two use cases do have something important in common. User interface code is
naturally event-driven (for example, binding event handlers to button clicks). Node.js makes this
a virtue by applying an event-driven approach to general-purpose programming.
JavaScript supports functions as first-class objects. This means it's easy to create functions
dynamically and pass around references to them. This fits in well with the asynchronous, non-
blocking approach of Node.js. In particular, it's easy to expose and use APIs based around
callback functions.
43.
A bright future
JavaScripthas received a lot of attention in the last several years as it has become more widely
used for providing rich functionality on the Web. Browser vendors have put a huge amount of
engineering effort into improving the performance of JavaScript. Node.js benefits from this
directly via its use of Chrome's V8 engine.
The JavaScript language itself is undergoing some major changes for the better. The ECMAScript
2015 standard (previously known as ES6) represents the most significant revision of the language
in its history. It introduces features that make the language more intuitive and less verbose. It also
addresses flaws that JavaScript has been criticized for in the past, removing gotchas and making
programs easier to reason about.
44.
When to useNode.js
As discussed earlier in this chapter, Node.js recognizes that I/O is a bottleneck for many
applications. On most programming platforms, threads will waste time blocking on I/O
operations. There are approaches developers can take to avoid this, but these all involve adding
some complexity to their code. In Node.js, the platform itself provides a completely natural
approach.
45.
Writing web applications
Theflagship use case for Node.js is building web applications. These are inherently event-driven
as most or all processing takes place in response to HTTP requests. Also, many websites do little
computational heavy-lifting of their own. They tend to perform a lot of I/O operations:
Streaming requests from the client
Talking to a database, locally or over the network
Pulling in data from remote APIs over the network
Reading files from disk to send back to the client
These factors make I/O operations a likely bottleneck for web applications. The non-blocking
programming model of Node.js allows web applications to make the most of a single thread. As
soon as any of these I/O operations starts, the thread is immediately free to pick up and start
processing another request. Processing of each request continues via asynchronous callbacks
when I/O operations complete. The processing thread is only kicking off and linking together
these operations, never waiting for them to complete. This allows Node.js to handle a much
higher rate of requests per thread than other platforms. You can also still make use of multiple
threads (for example, on multi-core CPUs) by simply running multiple instances of the Node.js
process.
46.
Identifying other usecases
There are of course some applications that don't perform much I/O and are more likely to be CPU
bound. Node.js would be less suitable for computationally-intensive applications. Programs that
do a lot of processing of in-memory data are less concerned about I/O.
Web applications are not the only I/O-heavy applications though. Other classes of program that
could be a good candidate for Node.js include the following:
Tools that manipulate large amounts of data on disk
Supervisor programs coordinating other software or hardware
Non-browser GUI applications that need to respond to user input
Node.js is especially suitable for glue applications that pull together functionality from other
remote services. The increasing popularity of microservices as an architectural pattern makes this
kind of application more common.
47.
Why now?
Node.js hasbeen around for several years, but now is the perfect time to start using it if you
haven't already.
The release of Node.js v4 towards the end of 2015 consolidated the project's governance model
and heralds Node.js coming to maturity. It also allows the project to keep more up to date with the
V8 engine. This means that Node.js can benefit more directly from ongoing development on V8.
For example, security and performance improvements to V8 will now make their way into
Node.js much sooner.
As discussed earlier in this chapter, the release of the ECMAScript 2015 standard makes
JavaScript a much more appealing language. It pulls in useful features from other popular OO
languages and resolves a number of long-standing flaws in JavaScript.
Meanwhile, the ecosystem of third party libraries and tools around Node.js and JavaScript
continues to grow. Node.js is treated as a first-class citizen by major hosting platforms.
Companies such as Google and Microsoft are also throwing their weight behind JavaScript and
related technologies.
48.
Summary
In this chapter,we have understood Node.js and its distinctive execution model, explored the
growing ecosystem around Node.js and JavaScript, seen the reasons for JavaScript as a language
choice, and described the kinds of application that can benefit from Node.js.
Now that you know how Node.js works and when to use it, it's time to dive in and get our first
Node.js application up and running.
49.
Chapter 2. GettingStarted with Node.js
This chapter will get you up and running with Node.js. You'll see how quick this can be and how
easy it is to start writing web applications. You'll also choose a development environment for
working with Node.js. In this chapter, we will cover the following topics:
Installing Node.js
Writing our first Node.js web application
Setting up our development environment
50.
Installing and runningNode.js
To install Node.js, visit https://nodejs.org, and download and run the installer package for the
currently recommended version. The examples in this book are based on Node.js v6, released in
April 2016 and supported through to April 2018.
After installation, open up a console window (run command prompt on Windows, or terminal on
Mac) and type node.
This opens the Node.js REPL, which works like the JavaScript console in browsers. Try typing in
a few commands and see the output:
> function square(x) { return x*x; }
undefined
> square(42)
1764
> new Date()
2016-05-02T16:08:41.915Z
> var foo = { bar: 'baz' }
undefined
> typeof foo
'object'
> foo.bar
'baz'
Now let's make use of one of the Node.js-specific APIs to create an HTTP server. Type the
following commands into the REPL(the output of each command is omitted from the listing below
for brevity):
> var listener = function(request, response) { response.end('Hello World!') }
> require('http').createServer(listener).listen(3000)
Now try visiting http://localhost:3000 in your browser. Congratulations! You have written
your first web server, in just two lines of code. The first line defines a callback function for
handling HTTP requests and returning a response. The second line sets up a new server that
accepts HTTP requests on port 3000 and invokes our callback function for each request.
You can exit the Node.js REPLby typing process.exit().
51.
Choosing an editor
Ofcourse, we're not going to write all of our code inside the REPL. You can use any text editor or
IDE you like for writing JavaScript for Node.js. If you're not sure what to use, try one of the
following:
Atom (https://atom.io/)
Visual Studio Code (https://code.visualstudio.com/)
These are both free, lightweight IDEs that are actually implemented in Node.js. They are both
available for Windows, Mac, and Linux.
The code listings in the rest of this book will be JavaScript source code files, not commands to be
typed into the REPL.
52.
Using an applicationframework
The server we created in the REPLused the low-level HTTP module built into Node.js. This
provides an API for creating a server that reads data from requests and writes to responses.
As with other programming platforms, there are frameworks available providing more useful
high-level abstractions for writing web applications. These include things such as URLrouting
and templating engines. ASP.NET MVC, Ruby on Rails, and Spring MVC are all examples of
such frameworks on different platforms.
Note
Example code
If you get stuck at any point in this book, you can follow along with the code at
https://github.com/NodeJsForDevelopers (there is a repository for each chapter and a commit for
each heading that introduces any new code).
In this book, we'll be using a framework called Express to write a web application in Node.js.
Express is the most popular web application framework for Node.js. It is well suited to small-
scale applications such as the one we'll be building. It also provides a good introduction to
important concepts. Most other popular Node.js web application frameworks are conceptually
similar to Express, and several are actually built on top of it.
53.
Getting started withExpress
To get our Express-based application started, we'll use npm to install the express-generator
package, which will create a skeleton application based on Express. Run the following command
in the console (that is, your regular terminal, not inside the Node.js REPL):
> npm install -g express-generator@~4.x
The -g option installs the Express generator globally, so you can run it from anywhere. The next
command we run will create a new folder to contain our application code, so run this command
wherever you want this folder to reside:
> express --hogan chapter02
Note
Templating engines
Express offers a choice of templating engines. We'll be using Hogan, which is an implementation
of the Mustache templating engine. You may already be familiar with Mustache from client-side
libraries. Don't worry if not, though. It's very simple to pick up.
As you can see from the output, this sets up a minimal standard application structure for us. Now
run the following command (as instructed by the generator output) to install the modules on which
our application depends:
> cd chapter02
> npm install
The generator has created a skeleton Node.js web application for us. Let's try running this:
> npm start
Now visit http://localhost:3000 again and you'll see the Express welcome page as shown
here:
There was alittle of everything in his “Ah!” A man falling from a
balloon must utter such an “Ah!” when he crashes against the
ground.
Meanwhile, twice the cheers burst forth. Hymns of welcome
were intoned, for silence had been kept till then. The duke had
appeared to be addressing himself to both the young girls. The
people did not know exactly which one might be the duchess; but
their enthusiasm knew no bounds all the same. A great eddy pushed
the crowd in a mass along the way to the castle, amid the blare of
trumpets and rattling of rifle-shots. The voivodes formed the
archway of steel above the heads of the duke and Helia, followed by
Ethel. Endless cheering saluted them: “Long live the duke! Long live
the duchess! Long live Morgana!”
“Well!” thought Caracal, “this is getting to be amusing. I had
thought all my chances lost, but they are coming back. Miss Ethel is
still free! Helia a duchess! Well, stranger things have been seen; but
all the same it is funny. After my ‘House of Glass’ and ‘Worms from a
Dung-hill’ I shall study from nature a ducal marriage and make it a
roman à clef! I shall write up every class of society—bourgeois,
peasants, and princes! He certainly will marry her: you can’t trifle
with an oath among such a population of fools; there are currents
you can’t stem.”
And so Caracal shouted louder than the others: “Long live
Morgana! Long live the duchess!” Then he offered his arm to Miss
Rowrer, who refused it!
“What are they crying ‘Long live the duchess!’ for?” she asked
Caracal, as they issued from beneath the steel arch, surrounded by
children who wafted kisses toward them and bombarded them with
flowers. Caracal recounted the oath which had been taken in
57.
presence of thepeople, and before God. The duke had sworn to
offer the heroine his titles and his throne.
“Poor duke!” thought Ethel; “he really believed it was I—
otherwise he would have sworn to nothing. Well, let it be so! We
shall see if an oath is a sacred thing, or if women are only dolls for
amusement. We shall see if the duke is a man!”
Ethel now knew the whole story. On the yacht, that very
evening, she had chanced to hear Helia talking with Suzanne. Their
few words had been a revelation to her. She had already imagined
what now she knew. The cow painting in the Luxembourg, the whole
little combination invented by Caracal, all the coarse horse-play—ah!
if Phil thought she was going to think less of him because of it, how
mistaken he was! All that was about as important to her as Mr.
Charley’s hair, brushed like a horse’s mane, and his velvet trousers—
less than nothing at all! But Phil had other reasons to blush for
himself, indeed. She understood his embarrassed air when he spoke
of Helia. That he should promise marriage with an oath, should give
hopes of happiness to Helia and lift her above her position, and then
thrust her back into her hard life—that Phil, a Christian and an
American, should do a thing like that! Ethel also knew the duke’s
love-making to Helia. Poor Helia! simply a plaything for those two
men!
58.
“The duke stoodalone”
She looked with admiration at the splendid couple before her,—
the duke and Helia,—without a glance at the two men beside her—
Phil and Caracal.
Helia was superb. The red lights, shaken by the wind,
illuminated her. The popular enthusiasm was beyond description; the
crowd pressed forward behind the torch-bearers along the way. They
touched her garments like the relics of a saint. The women lifted up
59.
their children tomake them see Morgana. Young girls sang in
chorus, while young men twirled their sabers aloft in warlike rhythm.
All at once, above the crowd, far away in the mountains flames
arose; the bonfires blazed up on each side of the bay and over the
cliffs. An immense blaze, like a giant torch, threw great shadows and
blinding streaks of light over the city. Its glow appeared through the
night, leaping over space from peak to peak, to the far horizon,
where it mingled with the stars.
Helia and Ethel were amazed at the grandeur of the sight, and
at the loving ardor of the crowd, in whose eyes, too, the flame
seemed burning. Their own beauty struck everybody; surely the new
duchess would be the most popular that Morgania had ever known,
to judge from the delirious enthusiasm let loose by her presence.
“What has taken hold of them?” thought Helia. “One might say I
had done something extraordinary.”
Helia for a moment was separated from Ethel. Beyond them the
way, lonely and bare, mounted up to the castle. Guards watched
over the approach. High above them the stained-glass window of
Morgana reflected glitteringly the torches and bonfires. In a few
steps more Helia, on the duke’s arm, would leave the people behind
her and mount up, followed by the nobles, to the Hall of Ancestors.
But just then there was a great rush forward, and as Helia, in
real fright at this wild enthusiasm, pressed against the duke, she felt
a sharp pain between her shoulders. She gave a little cry, and
struggled toward the open space before her; but her breath failed
and she fell.
“Oh, the coward!” she murmured. “He would never have dared
strike me to my face!”
60.
“What is thematter?” the duke said, grasping her in his arms,
“you are bleeding!”
“Oh! what has happened?” asked Ethel, who came up at this
moment, followed by Suzanne. “Helia! what has happened to you?”
“He has killed me!” said Helia.
“It is he who has done it!” cried Suzanne, with a terrible look,
searching for some one in the crowd.
“He—who?”
“Socrate!”
It was indeed Socrate. But he was no longer there. He had
already disappeared into the shadow, seized by avenging hands,
mangled by a people’s fury, trampled under foot into blood and mud!
Helia had guessed rightly. Socrate had come on board the
Columbia at Marseilles, where they had hastily taken on firemen.
Under the exasperation of want, he took this occasion to follow
Helia. He had learned as he prowled around the circus that she was
going to Morgania on Miss Rowrer’s yacht, and he was not the man
to let go his prey.
The events of the last day above all else had stirred him to fury.
Helia a duchess! Helia in grandeur, while he, the misunderstood
genius, should drag out his life in an attic! Ah! you will not be mine?
Then you shall be no one’s! He had seized the occasion and planted
his knife between Helia’s shoulders.
“Helia!” sobbed Suzanne. “Do you hear me? Answer!”
But Helia did not. The duke and Phil, terrified, bore her to the
throne-room. The torches cast a tragic light upon the group.
Immense shadows lengthened themselves out before them. The
61.
duke and Phil,bearing Helia, slowly advanced. The hall opened high
before them, lighted dimly.
62.
CHAPTER X
“ON YOURKNEES!”
They laid Helia down at the foot of Phil’s picture, on the great
ancestral throne on which the duke had hoped to seat himself beside
Miss Rowrer. The iron candelabrum, hanging from the arch, lighted
the hall. But Morgana’s stained window, more than all the rest,
blazed with sanguinary flashes. This time it was not the sunset, as
the duke had described it to Miss Rowrer, when he showed her the
engraving in Paris; it was the light of torches and of the giant bonfire
shining through it from without. The heroic statues, Thilda, Rhodaïs
the Slave, and Bertha the Horsewoman, seemed to live again
beneath the glow. The flashes of light from the window seemed to
make them palpitate. One would have said that joy swelled their
marble breasts when Helia, whose bodice had been undone, and
whose wounds were bandaged, opened her eyes and breathed freely
as she asked: “Where am I?”
“Oh, what a fright you’ve given us!” said Suzanne; “but now
you’re saved. Do you suffer?”
Helia was not suffering. To die was nothing,—but to fall, struck
from behind by such a man!
“If you had been there, Phil,” Helia said, speaking low, “you
would have protected me, would you not? Oh, with you I should fear
nothing. Give me your hand and stay with me!”
Phil, with downcast eyes full of tears, took her hand.
63.
“Look me inthe face; why do you lower your eyes, Phil?” she
said, so that he alone could hear her. She added, with an
indescribable regret in her voice: “Have I ever reproached you? Look
me in the face, as in the old days! I wish you to be happy. I do not
wish you to be sad!”
From the city came a confused murmur, like the noise of the sea;
and then there were long moments of silence. The nobles had not
dared to enter the hall. The people’s deep anxiety was making itself
felt. Suzanne, meanwhile, was arranging the cushions under Helia’s
head. The duke had gone a little away.
“Yes,” he was saying to himself, “Miss Rowrer will understand the
sacrifice I am making for her. I fail in my word, it is true, but she will
be grateful to me for not having made Helia her rival. As to the
people, Miss Rowrer’s millions will make them forget my perjury.”
Ethel, with Caracal at her elbow, gave to a servant the basin of
water and bloody cloths. Impassive as the marble ancestresses, she
turned her clear eyes on Phil and the duke.
“Phil,” Helia continued, as she pressed his hand, “you promised
me once—do you remember?—when you loved me, in the old days?
I understand, many things have passed since; and you are no longer
the same man. Come here, Phil, nearer, nearer! I want to tell a
secret in your ear. I have loved only you, Phil; every day I have
waited for you, and you never came! I was mad, I know; it was
impossible! But when one is young one is ignorant—and I believed
you! Now you love another. Phil, I forgive you; but leave your hand
in mine.”
Phil was silent and red with shame. Ah, indeed, he remembered!
Helia felt his heart beating in the hand which pressed her own. An
intense emotion overpowered him. He had the fearful calm which
goes before a storm. Neither the duke nor Phil spoke, motionless, by
64.
the side ofHelia, who was resting tranquilly, while they made a
room ready for her.
“You can get up and go to it by yourself,” said Suzanne. “You’re
safe. You haven’t lost much blood—Socrate’s blow missed!”
“What!” murmured Ethel. “Our heroic Helia is going to die in the
presence of these two men who loved her, without one of them
asking her pardon for their false oaths?”
“They accuse me of being cynical, but I should be more loyal
than that,” said Caracal, with his gaze fixed on Ethel.
“Look at your work, M. Caracal,” Ethel replied, in a low tone of
contempt. “Those two men are your pupils. The duke, who will not
see that the fortune of nations is courage and respect for promises—
and Phil, whom I thought more noble,—look at him, blushing with
shame, lowering his eyes,—these are the men according to your
heart! They are the men who consider woman a plaything, and
abandon her when she ceases to please! I forgive you your Richard
the Lion-hearted, your blackmailing, and your infamies, but look at
the result of your bad example and ignoble theories! When you
threw Helia at Socrate that you might study passion cheaply, without
knowing it you put the dagger in the assassin’s hand. Helia struck
down from behind,—it is your work! The duke, forgetful of duty and
aiming at Helia for his mistress, it is your work! Phil, with his false
promises, is worthy of you! Two men spoiled, one assassin, and a
dying woman—look at your work, M. Caracal!”
The “subtle observer,” a poor human rag blown down by a
breath, collapsed into a chair.
The great window still threw its burning glow upon the throne.
The marble ancestors, dimly lighted, seemed to lift their heads to
curse the feeble duke. They formed a circle round the hall and the
65.
throne where Heliawas resting—Helia, brave as Rhodaïs, intrepid as
Thilda, invulnerable as Bertha—Helia, the Morgana announced and
foretold. The duke was pale and grave. He looked at Helia, and then
turned his head toward Ethel.
All at once Ethel saw Helia rise upon her elbow, with one hand
convulsively grasping that of Phil, and the other signing to listen.
Through the half-open door floated a far-away melody, so weak, so
far away—Phil felt its thrill in his heart.
Le roi fait battre le tambour
Pour appeler ses dames,
Et la première qu’il a vue
Lui a ravi son âme.
The king had the drum beat
To call out his ladies—
And the first one he sees
Steals away his soul.
It seemed to come with the sea-breeze from beyond the
murmurs of the land. It was the music of the yacht playing the air
chosen by Ethel, that air which Helia hummed when she was alone.
Ethel had foreseen the hour when Helia would be entering the
throne-room. The music from the yacht was to greet her triumph.
Now it seemed to be soothing her agony.
“Listen, Phil, listen!” said Helia; “do you remember?”
Phil remembered all and saw all once more—his first love, the
little Saint John, the Louvre paradise, all his promises! His youth
blossomed in his heart.
66.
In his breastrose a flame which burned away every selfish
thought. Yes, he had promised! Helia had lived in that only hope; he
had let her fall from the height of her dream! He had shut off the
future from her. He had dug a pit with his selfishness, and pushed
Helia into it when she ceased to please! He had turned his back on
her despair!
It seemed to him that a giant hand was bending him low before
Helia and a voice was saying: “Down on your knees!”
Quickly, quickly and low, as one might confess a crime, Phil
spoke:
“Yes, I was wrong—yes, I promised. I ask pardon, Helia! How I
shall thank God if he will let you live, that I may blot out my fault!”
“Oh, Phil!” murmured Helia.
“I love you still,” said Phil; “and you shall be my wife. You will
see how happy we shall be—Helia, forgive me!”
67.
“‘My people awaittheir duchess’”
“Let me kiss your lips!” said Helia.
Ethel had drawn near, followed by Caracal. There was a strange
light in her eyes.
“See,” she said to Caracal. “Glory to those who are struck down
by the light like St. Paul. There is joy in heaven for the repenting
sinner!”
“Will you ever pardon me?” stammered Caracal.
68.
“Perhaps; tears washaway many things,” added Ethel,
remembering how Phil had already pardoned Caracal because he
had seen him weeping.
“That is a man worth loving, a rare thing,” Ethel thought as she
looked at Phil. Helia now was sitting up; the wound no longer bled.
“How happy I am!” said Helia.
She wept with joy. Phil was at her knees as in the old days.
“Listen,” she said, “it is our tune of the old times, Phil! I seem still to
be there!”
Phil kissed her hands to hide his tears.
“Phil,” said Helia, with a timid look at Ethel, and in a tone so low
that it could come only from the heart, “tell me, Phil, am I really fit
to be your wife?”
The door opened slowly, a bright light burst into the hall. It was
the voivodes coming for information. If a misfortune had happened
to one of the maidens, perhaps to their duchess, when they were on
the spot, sword in hand to form a sheltering arch above her—what a
shame it would be for them! If the duchess was dying, they would
pray for her on their knees. They approached in silence. The duke
had drawn near Ethel.
“I love you!” he said, speaking low. “See what I have done for
you! I swore—but I thought it was you. There is still time. My people
await their duchess. Shall it be you, Miss Rowrer?”
The duke held out his hand in an attitude of deepest respect.
Miss Rowrer stopped him short with a gesture. She had judged
the two men. This ruler who would not keep his oath, sworn in the
name of his ancestors—he should never be husband of hers. To her
titles were nothing, character was all. Calm as Justice, with her eyes
69.
fixed straight onthe duke, she pointed with her hand to Phil,
kneeling beside Helia, and said:
“That is a Man!”
70.
*** END OFTHE PROJECT GUTENBERG EBOOK FATA MORGANA: A
ROMANCE OF ART STUDENT LIFE IN 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
PLEASE READ THISBEFORE 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.
73.
1.C. The ProjectGutenberg 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
74.
Gutenberg” appears, orwith 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
75.
containing a partof 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
76.
payments must bepaid 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
77.
law in creatingthe 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.
78.
If the secondcopy 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™
79.
Project Gutenberg™ issynonymous 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
80.
Section 4. Informationabout 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
81.
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.
82.
Welcome to ourwebsite – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com