JavaScript Frameworks for Modern Web Dev 1st Edition Ambler Tim 2024 scribd download
JavaScript Frameworks for Modern Web Dev 1st Edition Ambler Tim 2024 scribd download
com
https://textbookfull.com/product/javascript-frameworks-for-
modern-web-dev-1st-edition-ambler-tim/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/web-application-security-
exploitation-and-countermeasures-for-modern-web-applications-1st-
edition-andrew-hoffman/
textboxfull.com
https://textbookfull.com/product/web-application-security-
exploitation-and-countermeasures-for-modern-web-applications-1st-
edition-andrew-hoffman-2/
textboxfull.com
https://textbookfull.com/product/javascript-on-things-hacking-
hardware-for-web-developers-lyza-danger-gardner/
textboxfull.com
https://textbookfull.com/product/learn-java-for-web-development-
modern-java-web-development-layka-vishal/
textboxfull.com
https://textbookfull.com/product/javascript-cookbook-programming-the-
web-3rd-edition-scott/
textboxfull.com
PHP Web Services APIs for the Modern Web 2nd Edition Lorna
Jane Mitchell
https://textbookfull.com/product/php-web-services-apis-for-the-modern-
web-2nd-edition-lorna-jane-mitchell/
textboxfull.com
https://textbookfull.com/product/ultimate-modern-jquery-for-web-app-
development-1st-edition-laurence-svekis/
textboxfull.com
I
Fa Ma Kn Re Grun nclu
ye ch oc q t, de
, Q , ko uir Ye s B
, A Mo ut eJ om o
sy ng , A S,B a we
nc o ng ro n, r,
.js ose ul w PM
, U , ar se 2
nd K n JS, rif ,
er ex, Kr y,
sco B ak
re, ook en
an she ,
d L lf,
od
as
h
www.it-ebooks.info
JavaScript Frameworks
for Modern Web Dev
Tim Ambler
Nicholas Cloud
www.it-ebooks.info
JavaScript Frameworks for Modern Web Dev
Copyright © 2015 by Tim Ambler and Nicholas Cloud
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with
reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed
on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or
parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its
current version, and permission for use must always be obtained from Springer. Permissions for use may be
obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under
the respective Copyright Law.
ISBN-13 (pbk): 978-1-4842-0663-8
ISBN-13 (electronic): 978-1-4842-0662-1
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol
with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director: Welmoed Spahr
Lead Editor: Louise Corrigan
Technical Reviewer: Robin Hawkes
Editorial Board: Steve Anglin, Mark Beckner, Gary Cornell, Louise Corrigan, James DeWolf,
Jonathan Gennick, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie,
Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing, Matt Wade, Steve Weiss
Coordinating Editor: Kevin Walter
Copy Editor: Bill McManus
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Cover Designer: Crest
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our Special
Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this text is available to
readers at www.apress.com/. For detailed information about how to locate your book’s source code, go to
www.apress.com/source-code/.
www.it-ebooks.info
There was a young lady named Laura,
Who was a beautiful señora.
Her love and assurance
Was a frequent occurrence
Which allowed me to write this book for yah.
—Tim
www.it-ebooks.info
Contents at a Glance
■
■Chapter 1: Bower��������������������������������������������������������������������������������������������������� 1
■
■Chapter 2: Grunt�������������������������������������������������������������������������������������������������� 11
■
■Chapter 3: Yeoman���������������������������������������������������������������������������������������������� 37
■
■Chapter 4: PM2���������������������������������������������������������������������������������������������������� 53
■
■Chapter 5: RequireJS������������������������������������������������������������������������������������������� 73
■
■Chapter 6: Browserify���������������������������������������������������������������������������������������� 101
■
■Chapter 7: Knockout������������������������������������������������������������������������������������������ 121
■
■Chapter 8: AngularJS���������������������������������������������������������������������������������������� 155
■
■Chapter 9: Kraken���������������������������������������������������������������������������������������������� 191
■
■Chapter 10: Mach���������������������������������������������������������������������������������������������� 251
■
■Chapter 11: Mongoose��������������������������������������������������������������������������������������� 297
■
■Chapter 12: Knex and Bookshelf����������������������������������������������������������������������� 345
■
■Chapter 13: Faye������������������������������������������������������������������������������������������������ 381
www.it-ebooks.info
■ Contents at a Glance
■
■Chapter 14: Q����������������������������������������������������������������������������������������������������� 395
■
■Chapter 15: Async.js����������������������������������������������������������������������������������������� 425
■
■Chapter 16: Underscore and Lodash����������������������������������������������������������������� 447
Index��������������������������������������������������������������������������������������������������������������������� 477
vi
www.it-ebooks.info
Contents
■
■Chapter 1: Bower��������������������������������������������������������������������������������������������������� 1
Getting Started����������������������������������������������������������������������������������������������������������������� 2
Configuring Bower������������������������������������������������������������������������������������������������������������ 2
The Manifest�������������������������������������������������������������������������������������������������������������������� 2
Creating a New Manifest������������������������������������������������������������������������������������������������������������������������ 3
Semantic Versioning��������������������������������������������������������������������������������������������������������� 6
Managing the Dependency Chain������������������������������������������������������������������������������������� 7
Creating Bower Packages������������������������������������������������������������������������������������������������ 8
Choose a Valid Name������������������������������������������������������������������������������������������������������������������������������ 8
Use Semver Git Tags������������������������������������������������������������������������������������������������������������������������������� 8
Publish Your Package to the Registry����������������������������������������������������������������������������������������������������� 9
Summary�������������������������������������������������������������������������������������������������������������������������� 9
vii
www.it-ebooks.info
■ Contents
■
■Chapter 2: Grunt�������������������������������������������������������������������������������������������������� 11
Installing Grunt��������������������������������������������������������������������������������������������������������������� 12
How Grunt Works������������������������������������������������������������������������������������������������������������ 12
Gruntfile.js�������������������������������������������������������������������������������������������������������������������������������������������� 12
Tasks���������������������������������������������������������������������������������������������������������������������������������������������������� 14
Plugins�������������������������������������������������������������������������������������������������������������������������������������������������� 14
Configuration���������������������������������������������������������������������������������������������������������������������������������������� 15
Creating Plugins������������������������������������������������������������������������������������������������������������� 32
Getting Started������������������������������������������������������������������������������������������������������������������������������������� 32
Creating the Task���������������������������������������������������������������������������������������������������������������������������������� 32
Publishing to npm��������������������������������������������������������������������������������������������������������������������������������� 35
Summary������������������������������������������������������������������������������������������������������������������������ 36
Related Resources��������������������������������������������������������������������������������������������������������� 36
viii
www.it-ebooks.info
■ Contents
■
■Chapter 3: Yeoman���������������������������������������������������������������������������������������������� 37
Installing Yeoman����������������������������������������������������������������������������������������������������������� 38
Creating Your First Project���������������������������������������������������������������������������������������������� 38
Subcommands�������������������������������������������������������������������������������������������������������������������������������������� 41
Summary������������������������������������������������������������������������������������������������������������������������ 52
Related Resources��������������������������������������������������������������������������������������������������������� 52
■
■Chapter 4: PM2���������������������������������������������������������������������������������������������������� 53
Installation���������������������������������������������������������������������������������������������������������������������� 53
Working with Processes������������������������������������������������������������������������������������������������� 54
Recovering from Errors������������������������������������������������������������������������������������������������������������������������ 56
Responding to File Changes����������������������������������������������������������������������������������������������������������������� 58
Monitoring Logs������������������������������������������������������������������������������������������������������������� 58
Monitoring Resource Usage������������������������������������������������������������������������������������������� 60
Monitoring Local Resources����������������������������������������������������������������������������������������������������������������� 60
Monitoring Remote Resources������������������������������������������������������������������������������������������������������������� 61
Advanced Process Management������������������������������������������������������������������������������������ 63
JSON Application Declarations������������������������������������������������������������������������������������������������������������� 63
Summary������������������������������������������������������������������������������������������������������������������������ 72
Related Resources��������������������������������������������������������������������������������������������������������� 72
ix
www.it-ebooks.info
■ Contents
■
■Chapter 5: RequireJS������������������������������������������������������������������������������������������� 73
Running the Examples���������������������������������������������������������������������������������������������������� 74
Working with RequireJS������������������������������������������������������������������������������������������������� 74
Installation�������������������������������������������������������������������������������������������������������������������������������������������� 75
Configuration���������������������������������������������������������������������������������������������������������������������������������������� 75
Application Modules and Dependencies����������������������������������������������������������������������������������������������� 78
Paths and Aliases��������������������������������������������������������������������������������������������������������������������������������� 81
Shims���������������������������������������������������������������������������������������������������������������������������������������������������� 84
Loader Plugins�������������������������������������������������������������������������������������������������������������������������������������� 88
Cache Busting��������������������������������������������������������������������������������������������������������������������������������������� 94
RequireJS Optimizer������������������������������������������������������������������������������������������������������� 96
Configuring r.js������������������������������������������������������������������������������������������������������������������������������������� 96
Running the r.js Command������������������������������������������������������������������������������������������������������������������� 97
Summary������������������������������������������������������������������������������������������������������������������������ 99
■
■Chapter 6: Browserify���������������������������������������������������������������������������������������� 101
The AMD API vs. CommonJS���������������������������������������������������������������������������������������� 102
Installing Browserify���������������������������������������������������������������������������������������������������� 102
Creating Your First Bundle�������������������������������������������������������������������������������������������� 103
Visualizing the Dependency Tree���������������������������������������������������������������������������������� 104
Creating New Bundles As Changes Occur�������������������������������������������������������������������� 105
Watching for File Changes with Grunt������������������������������������������������������������������������������������������������ 106
Watching for File Changes with Watchify������������������������������������������������������������������������������������������� 106
www.it-ebooks.info
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 120
Related Resources������������������������������������������������������������������������������������������������������� 120
■
■Chapter 7: Knockout������������������������������������������������������������������������������������������ 121
Views, Models, and View Models��������������������������������������������������������������������������������� 122
The Recipe List����������������������������������������������������������������������������������������������������������������������������������� 124
Recipe Details������������������������������������������������������������������������������������������������������������������������������������� 127
xi
www.it-ebooks.info
■ Contents
■
■Chapter 8: AngularJS���������������������������������������������������������������������������������������� 155
A Declarative Approach to Building Web Applications�������������������������������������������������� 155
The Imperative Approach�������������������������������������������������������������������������������������������������������������������� 155
The Declarative Approach������������������������������������������������������������������������������������������������������������������� 157
xii
www.it-ebooks.info
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 250
Related Resources������������������������������������������������������������������������������������������������������� 250
■
■Chapter 10: Mach���������������������������������������������������������������������������������������������� 251
Chapter Examples�������������������������������������������������������������������������������������������������������� 251
Installation�������������������������������������������������������������������������������������������������������������������� 252
Mach, the Web Server�������������������������������������������������������������������������������������������������� 252
HTTP Routes��������������������������������������������������������������������������������������������������������������������������������������� 254
Making Connections��������������������������������������������������������������������������������������������������������������������������� 260
Common Middleware�������������������������������������������������������������������������������������������������������������������������� 262
These Are Not the Routes You’re Looking for������������������������������������������������������������������������������������� 280
The Hosts with the Most��������������������������������������������������������������������������������������������������������������������� 282
Custom Middleware���������������������������������������������������������������������������������������������������������������������������� 287
xiii
www.it-ebooks.info
■ Contents
■
■Chapter 11: Mongoose��������������������������������������������������������������������������������������� 297
Basic MongoDB Concepts�������������������������������������������������������������������������������������������� 297
A Simple Mongoose Example��������������������������������������������������������������������������������������� 300
Creating a Mongoose Schema for JSON Data������������������������������������������������������������������������������������ 301
Importing Data with Mongoose���������������������������������������������������������������������������������������������������������� 302
Querying Data with Mongoose����������������������������������������������������������������������������������������������������������� 305
www.it-ebooks.info
■ Contents
Bookshelf��������������������������������������������������������������������������������������������������������������������� 361
What Is an Object-Relational Mapper?����������������������������������������������������������������������������������������������� 361
Creating Your First Bookshelf Model��������������������������������������������������������������������������������������������������� 362
Relationships�������������������������������������������������������������������������������������������������������������������������������������� 370
Summary���������������������������������������������������������������������������������������������������������������������� 379
Related Resources������������������������������������������������������������������������������������������������������� 379
■
■Chapter 13: Faye������������������������������������������������������������������������������������������������ 381
HTTP, Bayeux, and WebSockets������������������������������������������������������������������������������������ 381
WebSockets���������������������������������������������������������������������������������������������������������������������������������������� 383
The Bayeux Protocol��������������������������������������������������������������������������������������������������������������������������� 384
Summary���������������������������������������������������������������������������������������������������������������������� 393
Related Resources������������������������������������������������������������������������������������������������������� 394
■
■Chapter 14: Q����������������������������������������������������������������������������������������������������� 395
Timing Is Everything����������������������������������������������������������������������������������������������������� 395
Promises vs. Callbacks������������������������������������������������������������������������������������������������ 399
The Promise of Q���������������������������������������������������������������������������������������������������������� 401
Deferreds and Promises��������������������������������������������������������������������������������������������������������������������� 401
Values and Errors������������������������������������������������������������������������������������������������������������������������������� 406
Reporting Progress����������������������������������������������������������������������������������������������������������������������������� 412
Everything Ends���������������������������������������������������������������������������������������������������������������������������������� 415
Summary���������������������������������������������������������������������������������������������������������������������� 423
Related Resources������������������������������������������������������������������������������������������������������� 423
xv
www.it-ebooks.info
■ Contents
■
■Chapter 15: Async.js����������������������������������������������������������������������������������������� 425
Sequential Flow������������������������������������������������������������������������������������������������������������ 426
Parallel Flow����������������������������������������������������������������������������������������������������������������� 428
Pipeline Flow���������������������������������������������������������������������������������������������������������������� 430
Reusing a Pipeline������������������������������������������������������������������������������������������������������������������������������ 433
Summary���������������������������������������������������������������������������������������������������������������������� 446
■
■Chapter 16: Underscore and Lodash����������������������������������������������������������������� 447
Installation and Usage�������������������������������������������������������������������������������������������������� 449
Aggregation and Indexing�������������������������������������������������������������������������������������������� 449
countBy( )�������������������������������������������������������������������������������������������������������������������������������������������� 449
groupBy( )�������������������������������������������������������������������������������������������������������������������������������������������� 451
indexBy( )�������������������������������������������������������������������������������������������������������������������������������������������� 452
Chaining����������������������������������������������������������������������������������������������������������������������� 460
Function Timing������������������������������������������������������������������������������������������������������������ 463
defer( )������������������������������������������������������������������������������������������������������������������������������������������������ 463
debounce( )����������������������������������������������������������������������������������������������������������������������������������������� 465
throttle( )��������������������������������������������������������������������������������������������������������������������������������������������� 466
xvi
www.it-ebooks.info
■ Contents
Templates��������������������������������������������������������������������������������������������������������������������� 468
Loops and Other Arbitrary JavaScript in Templates���������������������������������������������������������������������������� 470
Living Without Gator Tags������������������������������������������������������������������������������������������������������������������� 472
Accessing the Data Object Within a Template������������������������������������������������������������������������������������ 473
Default Template Data������������������������������������������������������������������������������������������������������������������������ 474
Summary���������������������������������������������������������������������������������������������������������������������� 475
Related Resources������������������������������������������������������������������������������������������������������� 476
Index��������������������������������������������������������������������������������������������������������������������� 477
xvii
www.it-ebooks.info
About the Authors
Nicholas Cloud is a software developer who lives in the very humid city of
St. Louis. For over a decade he has forged his skills into a successful career.
He has developed web applications, web services, and desktop software on
diverse platforms with JavaScript, C#, and PHP. A strong proponent of open
source software, Nicholas contributes to userland projects and has written
several of his own open source libraries libraries. He speaks at a variety of
user groups and conferences and writes books, technical articles, and blog
posts in his spare time. He opines on Twitter at @nicholascloud.
xix
www.it-ebooks.info
About the Technical Reviewer
xxi
www.it-ebooks.info
Acknowledgments
This book would not have been possible without the encouragement and support of a number of people:
Nicholas Cloud, my friend and co-author, without whom this book would be much more limited
in scope and depth. His knowledge, experience, and steadfast dedication to this project have been
immeasurably helpful. Thank you.
Louise Corrigan, Kevin Walter, Christine Ricketts, Melissa Maldonado, and the rest of the staff at Apress
who supported us throughout the course of this project. I am grateful for the invitation that was extended to
embark upon this journey and for the ongoing support that you have provided.
Robin Hawkes, our technical reviewer. The examples and source code included with this book have
greatly benefited from his keen insight and sharp eye.
James Coglan, the creator of Faye. Thank you for taking the time to share your technical expertise
and feedback.
My friends and colleagues Greg Jones, Jeff Crump, Seth Steele, Jon Zumbrun, and Brian Hiatt. I am
grateful for your feedback and encouragement.
—Tim
Acknowledgements are slippery things. I have so many debts, and so little space to repay.
First, the debt to my co-author Tim who reached out and invited me on this journey. We’ve never met
in person but worked remotely as co-workers for about half a year—enough time for each of us to leave an
impression on each other across the miles. For his trust, encouragement, and constant effort I am grateful.
Second, my debt to the staff at Apress who guided us through the publishing process: Kevin, Louise,
Christine, and Melissa. Their patience and careful guidance spared you, the reader, from no small amount of
cringes, and kept me on my toes during the entire writing process. They are all sharp professionals with whom
I hope to work again some day.
Third, I am indebted to Robin for his excellent technical reviews; for reading and executing more code
samples than a developer should ever be tasked with groking.
Finally, I cannot repay the subject-matter expertise I gleaned from Michael Jackson (@mjackson) while
researching Mach, and Ryan Niemeyer (@RPNiemeyer) while researching Knockout—I can only pay it forward
to you, the reader.
—Nicholas
xxiii
www.it-ebooks.info
Introduction
They tell me we’re living in an information age, but none of it seems to be the information
I need or brings me closer to what I want to know. In fact (I’m becoming more and more
convinced) all this electronic wizardry only adds to our confusion, delivering inside scoops
and verdicts about events that have hardly begun: a torrent of chatter moving at the speed
of light, making it nearly impossible for any of the important things to be heard.
—Matthew Flaming, The Kingdom of Ohio
The notion that “technology moves quickly” is a well-worn aphorism, and with good reason: technology
does move quickly. But at this moment, JavaScript in particular is moving very quickly indeed—much like
that “torrent of chatter moving at the speed of light” that Matthew Flaming refers to in The Kingdom of Ohio.
The language is in the midst of what many have called a renaissance, brought about by the rapidly increasing
sophistication of browser-based applications and the rising popularity of JavaScript on the server, thanks to
Node.js.
An almost feverish pace of innovation is occurring within the JavaScript community that, while
endlessly fascinating to follow, also presents some unique challenges of its own. JavaScript’s ecosystem of
libraries, frameworks, and utilities has grown dramatically. Where once a small number of solutions for any
given problem existed, many can now be found… and the options continue to grow by the day. As a result,
developers find themselves faced with the increasingly difficult task of choosing the appropriate tools from
among many seemingly good options.
If you’ve ever found yourself wondering why JavaScript seems to be attracting so much attention lately,
as we have, it’s worth stopping for a moment to consider the fact that JavaScript, a language that was created
by one person in ten days, now serves as the foundation upon which much of the Web as we know it sits.
A language that was originally created to solve relatively simple problems is now being applied in new
and innovative ways that were not originally foreseen. What’s more, JavaScript is a beautifully expressive
language, but it’s not without its share of rough edges and potential pitfalls. While flexible, efficient, and
ubiquitous, JavaScript concepts such as the event loop and prototypal inheritance can prove particularly
challenging for those coming to the language for the first time.
For these and many other reasons, the development community at large is still coming to terms with
how best to apply the unique features that JavaScript brings to the table. We’ve no doubt only scratched
the surface of what the language and the community behind it are capable of. For those with an insatiable
appetite for knowledge and a desire to create, now is the perfect time to be a JavaScript developer.
We have written Pro JavaScript Frameworks for Modern Web Dev to serve as your guide to a wide
range of popular JavaScript tools that solve difficult problems at both ends of the development stack: in
the browser and on the server. The tutorials and downloadable code examples contained within this book
illustrate the usage of tools that manage dependencies, structure code in a modular fashion, automate
repetitive build tasks, create specialized servers, structure client side applications, facilitate horizontal
scaling, perform event logging, and interacting with disparate data stores.
The libraries and frameworks covered include Bower, Grunt, Yeoman, PM2, RequireJS, Browserify,
Knockout, AngularJS, Kraken, Mach, Mongoose, Knex, Bookshelf, Faye, Q, Async.js, Underscore, and Lodash.
xxv
www.it-ebooks.info
■ Introduction
In writing Pro JavaScript Frameworks for Modern Web Dev, our goal was to create a filter for the
“torrent of chatter” that often seems to surround JavaScript, and in so doing, to allow what we believe are
some important things to be heard. We hope the information contained within these pages proves as useful
to you as it has to us.
Grunt
Larry Wall, the creator of Perl, describes the three virtues of a great programmer as: laziness, impatience,
and hubris. In this chapter, we’ll focus on a tool that will help you strengthen the virtue of laziness - Grunt.
This popular task runner provides developers with a framework for creating command-line utilities
that automative repetitive build tasks such as running tests, concatenating files, compiling SASS / LESS
stylesheets, checking for JavaScript errors, and more. After reading this chapter, you’ll know how to use several
popular Grunt plugins, as well as how to go about creating and sharing your own plugins with the community.
xxvi
www.it-ebooks.info
■ Introduction
Yeoman
Yeoman provides JavaScript developers with a mechanism for creating reusable templates (“generators”)
that describe the overall structure of a project (initially required dependencies, Grunt tasks, etc…) in a way
that can be easily re-used over and over. Broad community support also allows you to take advantage of a
wide variety of pre-existing templates. In this chapter, we’ll walk through the process of installing Yeoman
and using several popular pre-existing generators. Finally, we’ll take a look at how we can create and share
our own templates with the community.
PM2
In this chapter, we will close out our discussion of development tools by taking a look at PM2, a command-line
utility that simplifies many of the tasks associated with running Node applications, monitoring their status,
and efficiently scaling them to meet increasing demand.
xxvii
www.it-ebooks.info
■ Introduction
Part 6: Communication
Faye
In this section, you’ll be introduced to Faye, a Node.js library that provides developers with a robust and
easy-to-use platform for building products that rely on real-time communication between servers and all
major browsers.Much of Faye’s popularity stems from the project’s goal of working everywhere the Web
works. Faye accomplishes this by providing seamless fallback support for a number of communication
protocols.
xxviii
www.it-ebooks.info
■ Introduction
Most examples are run with the Node.js runtime, which may be obtained from https://nodejs.org.
Chapters with additional prerequisites will explain the necessary procedures for downloading and
installing the examples. (For example, MongoDB is necessary to run examples in Chapter 11, which covers
Mongoose.)
Any additional steps necessary for running code examples (e.g., executing curl requests) or interacting
with a running example (e.g., opening a web browser and navigating to a specific URL) are explained
alongside each listing.
xxix
www.it-ebooks.info
Chapter 1
Bower
The concept of package management, also known as dependency management, is not new. Utilities within
this category provide developers with a mechanism for managing the various third-party libraries that a
project relies on. Widely used examples include
• npm: The package manager for Node.js
• Composer: A tool for dependency management in PHP
• pip: The PyPA recommended tool for installing Python packages
• NuGet: The package manager for the Microsoft development platform including .NET
While package management is hardly a new idea, a practice that has only recently begun to see
widespread adoption is the application of this concept to the management of front-end web assets—the
JavaScript libraries, stylesheets, fonts, icons, and images that serve as the building blocks of modern web
applications. The need for such structure has become evident as the foundations on which modern web
applications are built have grown in complexity. Web applications that once relied on a small selection of
broadly defined, “one size fits all” third-party libraries (e.g., jQuery) now find themselves using the work
of many more smaller libraries, each with a tightly defined purpose. Benefits of this approach include
smaller modules that are easier to test, as well as an enhanced degree of flexibility on the part of the
parent application, which can more easily extend third-party libraries or replace them altogether when
necessary.
This chapter is designed to get you up and running quickly with Bower, the front-end package manager
whose roots lie in open source initiatives at Twitter. Topics covered include
• Installing and configuring Bower
• Adding Bower to a project
• Finding, adding, and removing packages
• Semantic Versioning
• Managing the dependency chain
• Creating Bower packages
www.it-ebooks.info
Chapter 1 ■ Bower
Getting Started
All interaction with Bower occurs through a command-line utility that can be installed via npm. If you do not
already have Bower installed, you should install it before you continue, as shown in Listing 1-1.
■■Note Node’s package manager (npm) allows users to install packages in one of two contexts: locally
or globally. In this example, bower is installed within the global context, which is typically reserved for
command-line utilities.
Configuring Bower
Bower is configured on a per-project basis through a single (optional) JSON file that exists in your project’s
root folder, .bowerrc. For the purposes of this introduction, we’ll only look at the most frequently changed
setting within this file (see Listing 1-2).
Listing 1-2. The .bowerrc File from This Chapter’s Sample Project
// example-bootstrap/.bowerrc
{
"directory": "./public/bower_components"
}
By default, Bower will store your project’s dependencies in the bower_components folder. You will likely
want to change this location, and the directory setting allows you to do so.
The Manifest
Bower provides developers with a single point of entry from which third-party libraries can be found, added,
upgraded, and removed. As these actions occur, Bower updates a JSON file referred to as the “manifest”
with an up-to-date list of the project’s dependencies. The Bower manifest for this chapter’s sample project is
shown in Listing 1-3. In this example, Bower is aware of a single dependency, the Bootstrap CSS framework.
{
"name": "example-bootstrap",
"version": "1.0.0",
"homepage": "https://github.com/username/project",
www.it-ebooks.info
Chapter 1 ■ Bower
"authors": [
"John Doe <john.doe@gmail.com>"
],
"dependencies": {
"bootstrap": "3.2.0"
}
}
If we were to accidentally delete all of our project’s dependencies by removing the public/bower_
components folder, we could easily restore our project to its previous state by issuing a single command, as
shown next. Doing so would cause Bower to compare its manifest with our project’s current file structure,
determine what dependencies are missing, and restore them.
$ bower install
As a result of this behavior, we have the option of ignoring our project’s /public/bower_components
folder within version control. By committing only Bower’s manifest, and not the dependencies themselves,
our project’s source code can be kept in a cleaner state, containing only files that pertain directly to our
own work.
■■Note Opinions differ as to whether or not keeping your project’s dependencies out of version control is
a good idea. On the one hand, doing so results in a cleaner repository. On the other hand, this also opens the
door to potential problems should you (or the Bower registry, or GitHub, etc.) encounter connection issues.
The general consensus seems to be that if you are working on a “deployable” project (i.e., an application,
not a module), committing your dependencies is the preferred approach. Otherwise, keeping your project’s
dependencies out of version control is probably a good idea.
$ bower init
Finding Packages
One of the primary ways in which Bower can improve your development workflow is by providing you with a
centralized registry from which third-party libraries can be found. To search the Bower registry, simply pass
the search argument to Bower, followed by a keyword to search for, as shown in Listing 1-4. In this example,
only a short excerpt from the returned list of search results is shown.
www.it-ebooks.info
Chapter 1 ■ Bower
Search results:
jquery git://github.com/jquery/jquery.git
jquery-ui git://github.com/components/jqueryui
jquery.cookie git://github.com/carhartl/jquery-cookie.git
jquery-placeholder git://github.com/mathiasbynens/jquery-placeholder.git
Adding Packages
Each search result includes the name under which the package was registered, along with the URL of the
GitHub repository at which it can be accessed directly. Once we have located the desired package, we can
add it to our project as shown in Listing 1-5.
jquery#2.1.3 public/bower_components/jquery
■■Note Bower does not host any of the files associated with the packages contained within its registry; it
defers to GitHub for that responsibility. While it is possible to host packages at any URL, the majority of public
packages are found on GitHub.
Take note of the fact that in Listing 1-5, we pass the --save option to Bower’s install command. By
default, the install command will add the requested package to a project without updating its manifest.
By passing the --save option, we instruct Bower to permanently store this package within its list of
dependencies.
Listing 1-6 shows the HTML from this chapter’s sample project. After adding jQuery to our project via
Bower, we can load it via a script tag as we would any other library.
www.it-ebooks.info
Random documents with unrelated
content Scribd suggests to you:
raft might have appeared, even to close observation, to be no more
than a piece of drifting wood, but for the gleams sent forth from the
precious stones with which Marana’s silver hair-pins were set, and
for the ripple of Rayo’s paddle, which he contrived to ply as he lay.
The critical moment must be when he plunged, as there were no sea
sounds amidst which the splash might be lost. All was as quiet as a
lake. The guard-boat was no cradle to those who slept within it, for
it kept its place as if it had been fixed in the sand of the beach. The
black points of rock which rose above the surface at a distance
towards the land were reflected with perfect fidelity, instead of in
fluctuating lines of shadow. Marana dreaded the plunge for her lover,
and fearfully watched to see dark figures rise up in the guard-boat
while the circles were yet spreading, and breaking the moonlight to
shivers on the surface. No foe appeared, however; and Marana was
at liberty for new fears. There were enemies in the green depths
below more formidable than any to the right hand or the left. It was
quite as probable that a shark might take a fancy to this locality as a
diver; and a chance meeting was little likely to end without strife.
Marana drew towards the edge of the raft as its heavings subsided,
and looked eagerly down, dreading to see a red tinge diffuse itself in
the lucid depth, and starting at every shadow that floated through it.
She was fingering her ebony beads meanwhile, and her lips moved
as she murmured some aspirations compounded of a catholic prayer
and a native charm. The depth was little more than two fathoms in
this place, and Rayo was soon up again, though the minute of his
submersion seemed incalculably longer to Marana. He delivered his
pouch to her to be emptied, and rested himself by floating till he
was ready for another descent.
Again and again he dived, till Marana discovered a treasure in the
pouch which destroyed all further temptation to theft that night, and
relieved the damsel from the anxiety of watching more descents of
her lover. A shell which opened to the right, commonly called a right-
handed chank, a shell esteemed worth its weight in gold, appeared
in the heap, and it was not worth while to run any further risk when
so rare a possession as this was obtained. Rayo’s spirits were so
raised by his good fortune that he insisted on paddling quite round
the guard-boat, near enough to see whether there was any one in it,
while Marana looked anxiously at the ascending moon, whose flood
of light was now veiling the stars. When she saw arms gleaming in
the boat, she thought it too rash of her lover to come between the
sleeping guard and the moon, and looked imploringly at him while
she pointed to the shore. His curiosity once satisfied, the danger was
soon over. Rayo ventured to stand up to paddle, when the raft had
distanced the boat by half a mile, and Marana began her inquiries as
to what he had seen in the deep.
Rayo made light, as he had done for some time past, of the
achievement of diving for chanks. He had practised it as a
preparation for becoming a pearl-fisher in waters three times as
deep, and for a much more precious treasure. He was to make his
first trial of the nobler occupation at the approaching pearl fishery;
and he spoke with becoming indifference of all meaner
accomplishments. He had seen no sharks to-night; there would be
more chance of them in deeper water. He had been startled by no
strange appearances: nine fathoms down was the scene for
wonders. He had found no difficulty in filling his pouch: the oyster
beds would afford harder work. Marana thought all this was
counterbalanced by the absence of a charmer who might say
“avaunt!” to sharks, and interpret all marvels, and lighten all toils. If
her father could have been on the raft with them to-night, she
should think as little of the trip as Rayo himself; and if he could but
get himself engaged for the same boat that was to carry Rayo out to
his first pearl fishing, she should have confidence in his prosperity
and safe return.
They fell in with no other vessel till they came in sight of the
shore,—the wildest and dreariest part of the shores of Ceylon. A flat
yellow beach stretched away on either hand, without rock or tree, or
any object which could cast a shadow, except the huts of mud and
rushes which afforded a shelter to the natives. In no place was it
easier to make a landing, and in none was it more difficult to land
unperceived, when sun or moon was above the horizon. No jutting
rocks were there, behind whose screen a raft might lie concealed:
no shady creek into which a skiff might glide and secrete itself
beneath the mangroves: no groves of cocoa-nut, feathering the
margin of the tide, beneath whose canopy dusky pilferers might
creep to divide their spoils. All was here open to the sky, and to a
sky whose lesser lights leave little unrevealed even on the night of a
new moon.
Rayo and Marana had little chance of stealing to their homes
unobserved while so many eyes were looking upon them from
above, and while a certain pair of vigilant human eyes preserved
their wont of looking abroad upon the night. The tall figure of Father
Anthony, the priest, was moving on the beach, preceded by his still
taller shadow, when the raft floated on shore. Rayo saw this while
still afloat; and if he had been an English smuggler, he would have
pushed off again before he was recognized, and have kept out of
sight till Father Anthony was safely housed. But Rayo’s ideas of good
manners would not allow of this. He had no notion of failing to pay
his respects to any who came in his way, whatever might be the
consequence of the meeting; and he now greeted Father Anthony
with as much deference as Marana herself, hoping that it was no evil
which kept their friend awake at this hour.
“No worse evil than being unable to rest so well here as in Europe,
where there are no excessive heats of the day to make us restless at
night. But what fish do you seek so late? I fear you have lost your
nets,” he continued, seeing no fishing apparatus on board the raft.
Marana looked at Rayo, and Rayo said nothing.
“Chanks!” exclaimed Father Anthony, perceiving now of what
Marana’s burden consisted. “These chanks cannot be yours.”
“His hands brought them up,” declared Marana, pointing to her
lover.
“It may be so, but they are no more his than the comb in his hair
would be mine if I were to take it from him. Rayo, why did you steal
these chanks? Do not you know that God punishes theft?”
“Is it theft to get chanks for my bride, when I have worked long
for them, and can get no chanks by working? I thought God laid the
chanks in our seas for our brides.”
“They have become the property of some who may let your
brides, or the brides of India have them, as they may see fit. God
gave them into the hands of those who possess them; and He will
be angry with any who take them away by fraud or violence. All
cannot have these chank-beds, and those who have bought them
must be protected in their possession.”
“I have earned as many as I have taken,” replied Rayo; “and to-
night God has given them to me. The guard did not even stir when I
plunged.”
“And God gave him this,” added Marana, showing the precious
shell as an indubitable proof of all being right. Father Anthony had
not been long enough in his present station to know the full value of
what he now took into his hand; but if he had, his decision would
have been the same,—that the chanks were not Rayo’s.
Rayo was much in want of his friend’s guidance. In the school, it
was taught as a duty that a just reward should be given for toil. Was
it a duty out of school to toil without reward?
Certainly not, except in the case of the mutual services which
friends and neighbours should yield to each other. But nobody
thought of toiling without reward, as far as Father Anthony knew.
The chank-fishers, he was sure, were paid. Rayo acknowledged
having received certain portions of rice, and of cotton for clothing;
but never any wages which would purchase what was necessary for
Marana before her father would allow her to marry. Rayo had no
objection to work, but he had not doubted about the liberty of
paying himself, in case of an insufficiency of wages. When he heard,
however, all the denunciations that Father Anthony had to bring
against the sin of theft, and it was pressed upon him that he had
actually been guilty of the crime, he was perfectly submissive; no
less so than Marana, though his eyes did not stream like hers, and
he did not so instantly betake himself to his devotions. He stood with
his eyes cast down, waiting for instructions.
“Your duty is clear, Rayo,” said Father Anthony. “He that hath
stolen must not only steal no more, but must restore what he hath
stolen. When the sun rises, you must go to the owners of these
chanks and restore them, relating your offence and seeking their
pardon;—I need not say humbly, for I have never observed you fail
in humility.”
Rayo made obeisance, and Marana hoped he might also relate
how he fell into the offence.
“If he does it without any pretence of justifying himself,” said
Father Anthony, who was not unwilling that the facts of the
oppression under which his poor friends laboured should be brought
home, on every possible occasion, to the owners of the wealth which
surrounded them, and which they might not appropriate, “Rayo may
say why he wishes for chanks and for the money that chanks will
bring; but he must not defend himself for having taken them without
leave. Neither must you excuse yourself before God, Rayo; but seek
His pardon before you sleep. May He pardon and bless you, Rayo!”
“How far will you have to carry them?” asked Marana, as soon as
Father Anthony was out of hearing. “If it is not too far for a woman,
I will go with you, and carry them, and confess for you. How far
must they be carried.”
Rayo pointed to his father’s hut,—his own abode, and began
walking towards it with a countenance of perfect content. But
Marana stopped, and looked the entreaty which she dared not
speak.
“They are heavy,” observed Rayo, taking the chanks from her.
“No, no. I will carry them to the mountains,—I will swim with
them through the sea, sooner than that the curse shall light upon
you, Rayo. Father Anthony says the curse comes upon those who do
not do as they say, and a great curse upon those who steal as we
have done, unless they restore.”
“It will bring a curse to say what he bids me say to the rich men. I
shall fish no more chanks, and lose what I have got, and perhaps
fish no pearls. This will be a curse.”
“But what will Father Anthony say to-morrow?”
“Let us see if he finds it out.”
“But the curse will come, whether Father Anthony knows or not.”
“Your father shall charm it away, and you shall have your rings;
and the rest shall be sold at the fishery. Then we will build a house,
and we will each have new clothing, and we will be married.—But let
us hide the chanks. If my father finds them, he will sell some. If
Neyna finds them, she will ask for rings too. We will hide them in the
rushes.”
Marana dared not resist, but her horror of the curse grew every
moment. She did not think at all the worse of her lover for his
determination. She rather admired the bravery of it, her thoughts
being employed, not on the sin, but on its apprehended
consequences. She doubted whether her father had a charm strong
enough to obviate the effects of her lover’s rashness; and she was
far less afraid of anything that might come out of the rushes than of
what might come out of the deed which Rayo went to do there.
When the torches were lighted, without which it is unsafe to
penetrate the places where leopards may be crouching on dry sand,
hidden by the silky rushes, she went first, fearing, not the glaring
eye of a savage beast, but the vigilant glance of some saint or
demon whom her religion or the old superstitions of the country
taught her to regard as the dispenser of punishment from above.
She started as the night-wind swept among the reeds, not so much
from dread of some velvet paw that might be stealing towards her,
as from expectation of some token of wrath. All was quiet, however.
The curse was not perceived immediately to light, and the lovers
parted in safety at the door of her father’s hut.
Marana stood for some time hesitating between lying down at
once on her mat to sleep, and waking her father, to trouble him for a
charm without loss of time. A better plan than either flashed across
her mind, and found more and more favour the longer she
entertained it. It might avert the curse without exposing Rayo to
shame; and the loss of the chanks (which was involved in her
scheme) was a small price to pay for such security. She hoped Rayo
might be brought to think so; and if not, she could rather bear his
anger than see the curse light upon him. The chanks were intended
chiefly for her; and she could do without them for ornaments, and
had rather marry Rayo without a house and without new clothing,
than expose him to the curse: and thus, by a process of reasoning
over which the fear of a curse presided, she convinced herself that
the best thing she could do was to restore the chanks to their oozy
bed.
Without a torch, for she had not now the means of getting one,
she stole out, and crept to the hiding place among the rushes.
Without bite from snake, or alarm from any living thing more
formidable than a bat, she made her way out again. Without help or
hinderance, she pushed the little raft into the water, hoisted its mast
and mat, and stood out alone into the shining sea. What kind of
malignant beings she could imagine to be hovering between the
glorious constellations and their earthly mirror, it was for her to tell.
The miseries which she believed them commissioned to dispense
came from a much nearer place than the nearest of those radiant
spheres, or even of the dense clouds which began to show like a low
wall along the horizon. The miseries under the pressure of which her
lover had committed crime, and she was now dreading the
atonement, came from the corrupt desires and infirm judgments of
men near at hand, whose passion was for the possession of the
powers of the earth, and not for alliance with the powers of the air.
When Rayo rose in the morning at his father’s call, to trim the
boat for a fishing expedition, he was surprised to see no sign of his
little raft on the beach. It might have been washed away,—the sea
being no longer so smooth as it was a few hours before: or some
unscrupulous neighbour might have used it for his own convenience.
It was of little consequence; a raft being the simplest and cheapest
of all contrivances by which a Cingalese can set himself afloat.—The
disappearance was explained when old Gomgode’s flat-bottomed
fishing-boat, containing himself and Rayo, had made some progress
from the land, and was pitching in the rising swell, while the young
man threw out his nets.
“Rayo, Rayo,” said Gomgode, “what is floating out beyond? Rayo,
Rayo, tell me whether it is not your raft.”
Rayo believed it was, but could scarcely distinguish it yet with
sufficient certainty to claim it. The old man’s sight might not be
really better than his son’s, but it was usually sharpened by curiosity
to a much greater degree than that of the less vivacious Rayo. He
now perceived that there was a woman upon the raft, and then Rayo
also began to see very clearly;—and not only to see, but to act.
Gomgode could not conceive what possessed Rayo to draw in the
nets so hastily, and quit their station, and give up every thing for the
sake of following or meeting this raft, when to-day, of all days, it
was important to secure a good draught of fish. They had come out
early on purpose, the auction of the oyster-banks being just about to
be held, giving a fine opportunity for the sale of fish. One boat after
another was dropping out from the shore, and Rayo was losing all
the advantage of being out first,—was giving up all his preparations,
for the sake of making towards the raft.
“Rayo, Rayo,” the old man exclaimed.
“Father, Marana is there, dripping and struggling.”
“Is it Marana? It is Marana. What sent her out, Rayo? How long
has she been out, Rayo? Did you know that she had your raft, Rayo?
O, Rayo, what is she going to do now, Rayo?”
Marana was about to do a somewhat perilous thing. She was
about to dash through a threatening wave as a horserider bursts
through a blind hoop, trusting to light again. The sea was now far
too rough for so slight a machine as this raft. It pitched and shivered
as every wave broke over it, and afforded so little secure hold
against the stronger swells which succeeded each other, that Marana
seemed to find it her best way to pass through them separately. She
was seen standing with her face towards the approaching wave,
eyeing it steadily, and cleaving her way through it so as to come out
near the very point to which the raft was descending from its ridge.
This was all very well for awhile; but Marana was yet a great way
from shore, and it was scarcely possible but that such a succession
of plunges must exhaust her before she could commit herself finally
to the waves to be cast upon the beach. It was contrary to her
habits also to use much exertion, and the effort which brought her
out thus alone upon the sea,—whatever might be its motive,—could
hardly be long sustained. Rayo was full of wonder and of fear; and
his father’s remonstrances and questions stood little chance of being
attended to till Marana was safe on board.
Marana herself, though by far the most deferential person that
Gomgode was wont to meet, could scarcely bring herself to give an
answer to his inquiries till she had obtained Rayo’s forgiveness for
having, at great sacrifice to herself, averted the curse from him.
Meek and downcast, the dusky beauty stood before him, her half-
clothed frame trembling with her late exertions, and the salt water
dripping from her hair. One corner of her garment seemed to be very
carefully cherished by her. It contained the precious right-handed
chank. She had not found in her heart to part with it, on arriving at
the place of deposit: and, while hesitating, several good reasons for
keeping it occurred to her,—as is not unfrequently the case with
those who are religious after her manner, any more than with those
who are not religious at all. It was a pity the shell should be lost,
and it was likely never to be fished up among so many. It might be
turned to a much better purpose, if her father would make it a
charm. There could be no sin in keeping it, if it was thus converted
to a religious use instead of being sold for a profit. Marana therefore
kept the chank, and was the better able to bear her lover’s
displeasure from the silent consciousness that she held a treasure
for him in her possession.
She did not make a syllable of reply to his lowering look and few
cutting words against herself; and when his wrath turned upon
Father Anthony, or rather upon any priest or religion which interfered
with his doings, Marana testified only by a slight glance round her
that she was uneasy under this rashness of complaint.
The moment the boat touched the shore after a prosperous trip,
she hastened to her father’s cottage, not waiting to observe how
much more Gomgode would ask for his fish than they were actually
worth, nor even to hear whether anything was yet known of the
quality of the oysters which had been brought up as a sample from
the pearl banks, and on whose evidence the auction was to proceed.
She had an office to discharge, in common with her neighbours;—to
dress and light up the road by which the agent of the government
was to approach: and she was anxious to obtain the desired favour
from her father before she went forth.
The Charmer, who was expecting an application, in the course of
this day, to hold his services in readiness for the fishery, was now
absorbed in his preparations. He sat in a corner of his hut with his
documents spread before him. Strips of the talipot-leaf, on which
some consecrated style, guided by a wise man’s hand, had traced
mysterious characters, lay before the Charmer, and beads and
images and various sacred indescribable articles were scattered
around. He gave no heed to his child when she entered, and his
melancholy countenance wore a deeper sadness than usual.
“Father!” softly said Marana, after some time waiting his pleasure;
“where will the sharks be during the fishery?”
The Charmer shook his head, and acknowledged his doubt
whether St. Anthony would be permitted to keep them all within the
bounds of Adam’s Bridge, or whether some would be left at large
between the north banks and the shore. The south banks would be
safe; but the north, alas! were those in which Marana was
interested.
“Father! the monsoon will surely not arrive too early?”
“Not till April is nearly past,” he replied, cheerfully. “It is even likely
that there may be complaints in the south of drought, from the delay
of the rains. There will be no storms in our fishery.”
“I will ask Father Anthony to praise the saints.—Will the fishery be
rich?”
“To some, and not to others. This is commonly the case; and I
cannot discover whose countenances will be sad in Aripo, and whose
merry voices will sing along the shore at Condatchy, when the last
signal-gun has brought back the last boat.”
There was a long pause before Marana ventured to utter the more
important question,
“Father! will any one be waited for in the paradise under the sea?”
The Charmer rubbed his hand over his brow, and said that this
was the point he was endeavouring to ascertain when his daughter
entered. His indications were at variance; and whether the fishery
was to be fatal to none, or to more than he had put the question for,
he could not decide.—Marana felt that she must request Father
Anthony to intercede with, as well as praise the saints.
“Is it a blind day to you, father?” she inquired, struck by his tone
of doubt on almost every topic she had introduced.
“My blind days are many,” he replied, “and the blindness troubles
me. Marcair looks doubtfully upon me, and I look doubtfully upon
myself,—because I warned him that a wild elephant would tread his
rice-ground seven nights ago. Marcair lighted eleven fires, and thirty-
two friends kept watch with him for three nights; and not a twig was
heard to snap in the jungle: and those who laid ear to the ground
say that not so much as a panther trod within a mile.”
“Seven nights since? That was the night that ball of white fire
crossed the sky——”
“A ball of fire! St. Anthony opened your eyes to see it! A ball of
white fire cast from the hand of a saint is more fearful than eleven
fires kindled by men’s hands.”
“The elephant was scared, father, no doubt. The ball passed over
that very jungle, and then above Marcair’s rice-ground, and then into
the sea.”
The Charmer’s spirits were so raised by the news of this
interposition, that he presently contrived to bring his most important
calculations to an agreement, and then lost no time in charming the
shell, that his daughter might be at liberty to reveal to the
neighbours what she had seen on the seventh preceding night, and
thus re-establish her father’s credit.
She had never heard her father speak more positively on any point
than on this,—that if Rayo was married to her before he went out to
the fishery, this charm would bring Rayo back safe from the fishery.
—It followed that Rayo should have his wish, and be married before
the adventure. There being no dwelling ready nor any thing to put
therein, was a matter of small moment in comparison with Rayo’s
safety.
Marana went forth with her usual slow and demure step and
demeanour: but the torches which flashed here and there on her
path were reflected back from her eyes as brightly as from the
topazes on the crown of her head. With a lighter, but no less
graceful touch than usual, did she unfurl the fan-like talipot leaves of
which the tents for the strangers were composed. With more than
her usual fancy did she feather with cocoa-nut leaves the poles of
bamboo to which torches were to be fastened at intervals along the
road. She was too poor to pay the tribute of white cotton cloth for
the government agent to walk upon, when he should arrive within
sight of the huts: but she had a new song to offer, which was worth
full as much. She had, besides, a little cocoa-nut oil to spare for the
anointing of a sister beauty or two, when she had made her own
toilet: so that the remark went round that Marana must have got
some new charm from her father for her special adornment. Rayo’s
manner seemed to show that he thought so too.
Chapter II.
A MUSHROOM CITY.
During the time of the cinnamon harvest, it was the custom of Mr.
Carr, the agent of the East India Company for the management of
their cinnamon contract, to ride every morning through one
department or another of the Marandahn, or great cinnamon garden
near Columbo. The beauty of the ride might afford sufficient
temptation at any season of the year. The blue lake of Colombo,
whether gleaming in the sunrise, or darkening in the storms of the
monsoon, never lost its charms. The mountain range in the distance
was an object for the eye to rest lovingly upon, whether clearly
outlined against the glowing sky, or dressed in soft clouds, from
which Adam’s Peak alone stood aloft, like a dark island in the waters
that are above the firmament.
Whether the laurel-like cinnamon wore its early foliage of red or
its later of green, or its white blossom that made the landscape
dazzling with beauty and voluptuous with fragrance; whether the
talipot upreared its noble crest of straw-coloured blossoms above its
green canopy, or presented its clustering fruit; whether the cocoa-
nut tree bowed before the gusts of autumn, or stood in dark,
majestic clumps above the verdure of a less lofty growth, the groves
and gardens were a paradise to the eye of the Europeans.
The reaches of road, and the green paths which might be
detected here and there amidst the vast plantation, the rice grounds
and patches of meadow land interspersed, and the lowly roof
peeping out occasionally from beneath the palms, gave hints of the
presence of man and civilization; while the temple, with its oriental
dome supported on slender pillars, jutting out at the extreme end of
a promontory into the blue waters of the lake, or perched on some
point of the piled rocks in the background, carried back the thoughts
to old days of barbarian superstition. In all this there was so much
pleasure as to make a ride in the Marandahn a tempting pleasure at
all times and seasons; though Mr. Carr’s interest was at its height
during the cinnamon harvest.
As he was about to mount his horse one morning, the sound of
argument, not to say dispute, reached him from within.
“My dear child,” Mrs. Carr was saying, “Roomseree and Pellikee
shall give you an airing nearer home, so that you will not be killed
with the heat. Do not think of going with papa this morning.”
“O, mama, you know papa says nothing tires me. I can ride as far
as papa; and papa says he likes to show me what the people are
doing; and I am sure the people like me to go too. Papa enjoys his
ride so much more when I go with him; and the horse does not
think me very heavy.”
“Heavy! no, love! You are so small and slight, Alice, that it makes
me tremble to think of your going out under such a sun as it will be
by the time you get back. Papa always promises to take a very short
ride; and it ends with his bringing you home at the end of four or
five hours. Better stay with me, love.”
“All the rest of the day, mama; but papa has had the right saddle
put on, and we are to go the west ride this morning. Cannot you go
to sleep till we come back?”
Mrs. Carr promised to try; and, to do her justice, she was always
ready to do her best to sleep, day and night, bidden and unbidden.
With a few sighs over the charming spirits and the unquenchable
curiosity of the dear child, she closed her eyes on the dewy radiance
of a morning in paradise, and was glad that she had nothing more to
do with cinnamon than to be tired of hearing of it, and to taste it
when she pleased.
Alice used her eyes to more purpose this morning. She was yet
new enough to scenes like those before her to be full of wonder, and
other feelings, as natural, perhaps, but less desirable.
“Papa, do giants live in this place?”
“Giants, my dear, no. What made you fancy such a thing? You
have seen no very amazing people, have you?”
“No; they are very small pretty people, I think. Sometimes, when I
see them under such a very tall clump of trees as that, or among the
jungle grass, they put me more in mind of dark fairies than giants;
but——”
“But the trees are some of them fit for giants’ walking-sticks, I
suppose you think; and an elephant is a very proper animal for a
giant to ride. Hey?”
“I have seen men on elephants,” replied Alice. “But look there!
Look at that great castle!” And she pointed with awe to a mighty
object which was partially revealed as the morning mists drew off.
“That is not a castle, my dear; though I do not wonder at your
taking it for one. It is a mountain-peak.”
“But the drawbridge, papa;—the drawbridge hanging in the air.”
“Ah! you would be a long time in finding out what that drawbridge
(as you call it) is. You think it made for giants; but it would break
down under your weight. That is only a bridge of creeping plants, for
birds and butterflies to hide in. If a strong wind came, you would see
it swing, like your swing between the cherry trees in the orchard at
your grandmama’s, in England.—When we get out of the garden and
nearer the thickets, you will see some such flowers as that bridge is
made of, hanging from the trees, and binding them together so that
we cannot ride through them.”
“But I do not want to get out of the garden yet. Here come the
people, one after another, from their cottages, with their crooked
knives to cut down the branches. What are those tawny people
doing in the shade? They seem to be sitting very comfortably, all in a
ring. This is prettier than seeing grandmama’s mowers in England,
besides that the mowers do not sing at their work, like these
people.”
“The mowers in England have more reason to sing than many of
these peelers. Look how thin many of them are; and that poor child
playing in the grass appears half-starved. Very few people in England
are so poor as some of the natives here, who yet sing from morning
till night.”
Alice observed that they were not all thin; and she pointed to one
man whose legs were of an enormous size, and to another whose
body was nearly as broad as it was long.—She was told that these
appearances were caused by disease; and that the diseases of the
labourers were in a great degree owing to their poor way of living.
There would be few such swollen or emaciated bodies as these if the
people had flesh to eat, or good bread, or even the seasoning which
was necessary to make their vegetable food agree with them.
“Seasoning! What sort of seasoning?”
“Salt, and pepper, and cardamoms, and cinnamon.”
“Salt, papa! They must be very lazy if they do not get salt enough.
There is the sea all round Ceylon; and I have seen several ponds
where the water was so salt I could not drink it. There was a crust
of salt all about the edge, papa.”
“Very true, my dear; but the people are not allowed to take it. The
king of Candy lives in the middle of this island; and the kings of
Candy have sometimes been troublesome people to the English, as
they were to the Dutch before them. Now, as the king of Candy
cannot get to the sea, or to any salt lake, without our king’s leave,
he and his people depend upon us for salt; and our government likes
to keep him quiet, and get a great price for its salt at the same time
by selling it to the Candians very dear, and by letting nobody else
sell any. So the people of the country are not allowed to help
themselves to salt.”
“But if there was not enough, I would rather make the king of
Candy go without than these poor people who belong to us. We
ought to take care of them first.”
“The government likes to take care of itself before either its own
people or the Candians. There is salt enough for every body here,
and for half India besides; and large quantities are destroyed every
year, to keep up the price, while many are dying for want of it, and
those who live can get nothing better than coarse dirty salt which
the beasts in your grandmama’s farm-yard would turn away from. If
we could count the numbers of Hindoos who die in India for want of
the salt which their own country produces, we should find that a
fearful reckoning awaits the Company there, as there does the
government here; a fearful balance of human life against a high
price for salt.”
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com