100% found this document useful (1 vote)
21 views

Download Full Stack JavaScript: Learn Backbone.js, Node.js, and MongoDB - Second Edition Azat Mardan ebook All Chapters PDF

MongoDB

Uploaded by

hirterlydin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
21 views

Download Full Stack JavaScript: Learn Backbone.js, Node.js, and MongoDB - Second Edition Azat Mardan ebook All Chapters PDF

MongoDB

Uploaded by

hirterlydin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Download Full Version ebook - Visit ebookmeta.

com

Full Stack JavaScript: Learn Backbone.js, Node.js,


and MongoDB - Second Edition Azat Mardan

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

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

Full Stack JavaScript 1st Edition Azat Mardan

https://ebookmeta.com/product/full-stack-javascript-1st-edition-azat-
mardan/

ebookmeta.com

Modern Full-Stack Development: Using TypeScript, React,


Node.js, Webpack, Python, Django, and Docker 2nd Edition
Frank Zammetti
https://ebookmeta.com/product/modern-full-stack-development-using-
typescript-react-node-js-webpack-python-django-and-docker-2nd-edition-
frank-zammetti/
ebookmeta.com

Modern Full-Stack Development: Using TypeScript, React,


Node.js, Webpack, Python, Django, and Docker 2nd Edition
Frank Zammetti
https://ebookmeta.com/product/modern-full-stack-development-using-
typescript-react-node-js-webpack-python-django-and-docker-2nd-edition-
frank-zammetti-2/
ebookmeta.com

Alpha Bear 1st Edition Bianca D Arc

https://ebookmeta.com/product/alpha-bear-1st-edition-bianca-d-arc/

ebookmeta.com
Strange Code Esoteric Languages That Make Programming Fun
Again 1st Edition Ronald T. Kneusel

https://ebookmeta.com/product/strange-code-esoteric-languages-that-
make-programming-fun-again-1st-edition-ronald-t-kneusel/

ebookmeta.com

MS-700 Managing Microsoft Teams Exam Guide - Second


Edition Peter Rising

https://ebookmeta.com/product/ms-700-managing-microsoft-teams-exam-
guide-second-edition-peter-rising/

ebookmeta.com

Wonky Inn 03 0 Weird Wedding at Wonky Inn 1st Edition


Jeannie Wycherley

https://ebookmeta.com/product/wonky-inn-03-0-weird-wedding-at-wonky-
inn-1st-edition-jeannie-wycherley/

ebookmeta.com

Contentious Cities Design and the Gendered Production of


Space 1st Edition Jess Berry Editor Timothy Moore Editor
Nicole Kalms Editor Gene Bawden Editor
https://ebookmeta.com/product/contentious-cities-design-and-the-
gendered-production-of-space-1st-edition-jess-berry-editor-timothy-
moore-editor-nicole-kalms-editor-gene-bawden-editor/
ebookmeta.com

University Success Oral Communication Advanced, Student


Book with MyEnglishLab 1st Edition Cavage

https://ebookmeta.com/product/university-success-oral-communication-
advanced-student-book-with-myenglishlab-1st-edition-cavage/

ebookmeta.com
Wild Oat Milk Accidentally Breedy With Benefits Spice in
the Mountains Book 3 1st Edition Elena Dawne

https://ebookmeta.com/product/wild-oat-milk-accidentally-breedy-with-
benefits-spice-in-the-mountains-book-3-1st-edition-elena-dawne/

ebookmeta.com
Full Stack
JavaScript
Learn Backbone.js,
Node.js, and MongoDB

Second Edition

Azat Mardan
Full Stack JavaScript
Learn Backbone.js,
Node.js, and MongoDB
Second Edition

Azat Mardan
Full Stack JavaScript: Learn Backbone.js, Node.js, and MongoDB
Azat Mardan
San Francisco, California, USA

ISBN-13 (pbk): 978-1-4842-3717-5 ISBN-13 (electronic): 978-1-4842-3718-2


https://doi.org/10.1007/978-1-4842-3718-2
Library of Congress Control Number: 2018962263

Copyright © 2018 by Azat Mardan


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.
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, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Louise Corrigan
Development Editor: James Markham
Coordinating Editor: Nancy Chen
Cover designed by eStudioCalamar
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 [email protected], or visit http://www.apress.com/
rights-permissions.
Apress titles 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 Print and eBook
Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484237175. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
To my parents, Almas and Alsu, who bought
me my first computer, and let me use the phone
line for dial-up Internet.
Table of Contents
About the Author���������������������������������������������������������������������������������xi
Acknowledgments�����������������������������������������������������������������������������xiii
Preface�����������������������������������������������������������������������������������������������xv
Introduction��������������������������������������������������������������������������������������xvii

Part I: Quick Start������������������������������������������������������������������������1


Chapter 1: Basics���������������������������������������������������������������������������������3
Front-End Definitions��������������������������������������������������������������������������������������������4
Web Request Cycle������������������������������������������������������������������������������������������5
Mobile Development����������������������������������������������������������������������������������������6
HyperText Markup Language���������������������������������������������������������������������������8
Cascading Style Sheets���������������������������������������������������������������������������������12
JavaScript������������������������������������������������������������������������������������������������������14
Agile Methodologies��������������������������������������������������������������������������������������������27
Scrum������������������������������������������������������������������������������������������������������������27
Test-Driven Development������������������������������������������������������������������������������29
Continuous Deployment and Integration�������������������������������������������������������29
Pair Programming�����������������������������������������������������������������������������������������30
Back-End Definitions������������������������������������������������������������������������������������������31
Node.js�����������������������������������������������������������������������������������������������������������31
NoSQL and MongoDB������������������������������������������������������������������������������������33
Cloud Computing�������������������������������������������������������������������������������������������33

v
Table of Contents

HTTP Requests and Responses���������������������������������������������������������������������34


RESTful API����������������������������������������������������������������������������������������������������35
Summary������������������������������������������������������������������������������������������������������������37

Chapter 2: Setup���������������������������������������������������������������������������������39
Local Setup���������������������������������������������������������������������������������������������������������40
Development Folder��������������������������������������������������������������������������������������40
Browsers�������������������������������������������������������������������������������������������������������42
IDEs and Text Editors�������������������������������������������������������������������������������������43
Version Control Systems��������������������������������������������������������������������������������45
Local HTTP Servers���������������������������������������������������������������������������������������������46
Database: MongoDB��������������������������������������������������������������������������������������47
Required Components�����������������������������������������������������������������������������������52
Node.js Installation����������������������������������������������������������������������������������������52
Browser JavaScript Libraries������������������������������������������������������������������������54
Less App��������������������������������������������������������������������������������������������������������55
Cloud Setup���������������������������������������������������������������������������������������������������������55
SSH Keys�������������������������������������������������������������������������������������������������������55
GitHub�����������������������������������������������������������������������������������������������������������������58
Microsoft Azure���������������������������������������������������������������������������������������������������59
Heroku����������������������������������������������������������������������������������������������������������������61
Summary������������������������������������������������������������������������������������������������������������63

Part II: Front-End Prototyping���������������������������������������������������65


Chapter 3: Getting Data from Backend Using jQuery and Parse���������67
Definitions�����������������������������������������������������������������������������������������������������������68
JavaScript Object Notation����������������������������������������������������������������������������68
AJAX��������������������������������������������������������������������������������������������������������������70
Cross-Domain Calls���������������������������������������������������������������������������������������71

vi
Table of Contents

jQuery Functions�������������������������������������������������������������������������������������������������72
Bootstrap������������������������������������������������������������������������������������������������������������74
Less���������������������������������������������������������������������������������������������������������������������79
Less Variables������������������������������������������������������������������������������������������������79
Less Mix-ins��������������������������������������������������������������������������������������������������80
Less Operations���������������������������������������������������������������������������������������������82
An Example Using a Third-Party API (OpenWeatherMap) and jQuery������������������84
Parse�������������������������������������������������������������������������������������������������������������������96
Message Board with Parse Overview���������������������������������������������������������������107
Message Board with Parse: REST API and jQuery Version��������������������������109
Pushing to GitHub����������������������������������������������������������������������������������������119
Deployment to Microsoft Azure�������������������������������������������������������������������������121
Deployment of Weather App to Heroku�������������������������������������������������������������122
Updating and Deleting Messages���������������������������������������������������������������������125
Summary����������������������������������������������������������������������������������������������������������126

Chapter 4: Intro to Backbone.js��������������������������������������������������������127


Setting Up a Backbone.js App from Scratch�����������������������������������������������������128
Backbone.js Dependencies�������������������������������������������������������������������������������128
Working with Backbone.js Collections��������������������������������������������������������������133
Backbone.js Event Binding��������������������������������������������������������������������������������141
Backbone.js Views and Subviews with Underscore.js��������������������������������������147
Refactoring Backbone.js Code��������������������������������������������������������������������������159
AMD and Require.js for Backbone.js Development�������������������������������������������168
Require.js for Backbone.js Production��������������������������������������������������������������179
Super Simple Backbone.js Starter Kit���������������������������������������������������������������185
Summary����������������������������������������������������������������������������������������������������������185

vii
Table of Contents

Chapter 5: Backbone.js and Parse����������������������������������������������������187


Message Board with Parse: JavaScript SDK and Backbone.js Version�������������188
Taking Message Board Further�������������������������������������������������������������������������208
Summary����������������������������������������������������������������������������������������������������������209

Part III: Back-End Prototyping�������������������������������������������������211


Chapter 6: Intro to Node.js���������������������������������������������������������������213
Building “Hello World” in Node.js����������������������������������������������������������������������214
Node.js Core Modules���������������������������������������������������������������������������������������216
http��������������������������������������������������������������������������������������������������������������216
util���������������������������������������������������������������������������������������������������������������217
querystring��������������������������������������������������������������������������������������������������218
url����������������������������������������������������������������������������������������������������������������218
fs�����������������������������������������������������������������������������������������������������������������218
npm Node.js Package Manager������������������������������������������������������������������������219
Deploying “Hello World” to PaaS�����������������������������������������������������������������������222
Deploying to Microsoft Azure����������������������������������������������������������������������������222
Deploying to Heroku������������������������������������������������������������������������������������������223
Message Board with Node.js: Memory Store Version����������������������������������225
Unit Testing Node.js�������������������������������������������������������������������������������������225
Summary����������������������������������������������������������������������������������������������������������237

Chapter 7: Intro to MongoDB������������������������������������������������������������239


MongoDB Shell��������������������������������������������������������������������������������������������������240
BSON Object ID�������������������������������������������������������������������������������������������������242
MongoDB Native Driver�������������������������������������������������������������������������������������243
MongoDB on Heroku: MongoLab�����������������������������������������������������������������������246
Message Board: MongoDB Version�������������������������������������������������������������������252
Summary����������������������������������������������������������������������������������������������������������256
viii
Table of Contents

Chapter 8: Putting Frontend and Backend Together�������������������������257


Adding CORS for Different-Domain Deployment�����������������������������������������������258
Message Board UI���������������������������������������������������������������������������������������������260
Message Board API�������������������������������������������������������������������������������������������268
Deployment to Heroku��������������������������������������������������������������������������������������274
Same-Domain Deployment Server��������������������������������������������������������������������275
Deployment to Amazon Web Services���������������������������������������������������������������282
Summary����������������������������������������������������������������������������������������������������������287

Chapter 9: Conclusion�����������������������������������������������������������������������289

Appendix: Further Reading���������������������������������������������������������������291


Free JavaScript and Node Resources���������������������������������������������������������������291
Good JavaScript Books�������������������������������������������������������������������������������������292
Good Node.js Books������������������������������������������������������������������������������������������292
Interactive Online Classes and Courses������������������������������������������������������������293
Startup Books and Blogs�����������������������������������������������������������������������������������293

Index�������������������������������������������������������������������������������������������������295

ix
About the Author
Azat Mardan has over 18 years of experience
in web, mobile, and software development.
With a Bachelor’s degree in Informatics and
a Master of Science degree in Information
Systems Technology, Azat possesses deep
academic knowledge as well as extensive
practical experience. Azat is an experienced
software engineer, author, and educator. He
has published 16 books and counting.
Currently, Azat works as a Software
Engineering Leader at Indeed.com, the number one job search site. Before
Azat worked as a Technology Fellow at Capital One Financial Corporation,
a top 10 USA bank. Even before that, Azat was a Team Lead at DocuSign,
where his team rebuilt 50 million user products (DocuSign web app) using
the tech stack of Node.js, Express.js, Backbone.js, CoffeeScript, Jade, Stylus,
and Redis.
Recently, he worked as a senior engineer at the curated social media
news aggregator web site, Storify.com (now part of Adobe), which
is used by BBC, NBC, CNN, the White House, and others. Storify runs
everything on Node.js unlike other companies. It’s the maintainer of the
open source library jade browser.
Before that, Azat worked as a CTO/Cofounder at Gizmo—an enterprise
cloud platform for mobile marketing campaigns, and has undertaken the
prestigious 500 Startups business accelerator program.

xi
About the Author

Azat also has past experience developing mission-critical applications


for government agencies in Washington, DC, including the National
Institutes of Health, the National Center for Biotechnology Information,
and the Federal Deposit Insurance Corporation, as well as for Lockheed
Martin.
Azat is a frequent attendee at Bay Area tech meet-ups and hackathons
(AngelHack hackathon ’12 finalist with team FashionMetric.com, which
went on to raise venture capital from Mark Cuban and TechStars).
In addition, Azat teaches technical classes at General Assembly, Hack
Reactor, pariSOMA, and Marakana (acquired by Twitter) to much acclaim.
In his spare time, he writes about technology on his blog: Webapplog.
com, which was a number one in “express.js tutorial” Google search results
for some time.
Azat is also the author of Pro Express.js, Practical Node.js, Node Program
(http://nodeprogram.com/) and others. Azat is the creator of open
source Node.js projects, including ExpressWorks, mongoui, and HackHall.
You can reach Azat and say hi using one of these methods:
Twitter: @azatmardan https://twitter.com/azatmardan - Azat
loves getting “Hi” on Twitter
LinkedIn: linkedin.com/in/azatm
Blog: webapplog.com
GitHub: github.com/azat-co/fullstack-javascript

xii
Acknowledgments
I would like to thank the team of early Node contributors bringing
JavaScript to the servers. Without them, the full stack JavaScript
development wouldn’t be possible.
Thank you to the supporters of my Kickstarter campaign to write the
second edition of this book and do so in the open on GitHub. Without
you I probably would have not worked on this release so hard and maybe
not worked at all. You are AWESOME because you made this new edition
a reality and not only that but you have made this edition and previous
edition available on GitHub for the entire world to read and learn Node
which is the greatest technology for building web applications ever.
In particular, very great many thanks to individual Kickstarter
supporters (who will soon get the signed print books and other rewards or
maybe already have them): Matthew Amacker, Jordan Horiuchi, Tim Chen,
Alexey Bushnev, Aleksey Maksimov, Maurice van Cooten, Ryan, Ng Yao
Min, Kommana Karteek, Elias Yousef, Arhuman, Javier Armendariz, Dave
Anderson, Edithson Abelard. You guys are brilliant!
I cannot not mention the biggest supporter DevelopIntelligence,
which is one of the best if not the best tech training companies in the world
(http://www.developintelligence.com). So if you need to train your
software engineers in… anything! Then email them. Seriously, Develop
Intelligence has been around for 10+ years, and they have great teachers
with great technical classes. I was one of their instructors so I know. :)
I’m grateful to my copy and content editors at Apress, specifically to
James Markham, Louise Corrigan, Teresa Horton, and Karen Jameson.
They accomplished an amazing feat by bringing this book to life in a span
of a few weeks.

xiii
Acknowledgments

Also, I’m grateful to the students of Hack Reactor, Marakana,


pariSOMA, and General Assembly where I taught and used early Full Stack
JavaScript (or its parts) training material.
Once again, big thanks goes to Develop Intelligence who backed my
effort to open source the manuscript of this book and allowed me to work
in the open with early readers. I taught many corporate workshop on
React, Node, cloud, and JavaScript to clients of Develop Intelligence. If you
wants a world-class on-site tech training, go to developintelligence.com
and book the class.

xiv
Preface
I’m writing this as I’m sitting at the San Francisco airport waiting for
my flight to Portland, Oregon, for the biggest Node.js conference. I’ll be
speaking there about Node.js. It’s scary and funny at the same time to
think that I started to learn Node only three years ago. Yes, I remember
how I decided that the best way to learn is to teach others. For this reason I
started teaching my first Node classes and writing this book. The book was
mostly for me, so I could remember how to push Heroku or how to create
Node servers that talk to MongoDB. It was called Rapid Prototyping with
JS back then. Three years sped away; I published a few more Node books
as well as released several Node apps in production; and in 2014, Apress
approached me wanting to publish an updated edition under a new title.
I can't believe this is the second editon of the book. It's 2018 and a lot of
thing changes. I am glad for the evolution of JavaScript and innovation in
the Node.js space.
The main reason I bet my time and energy on JavaScript and Node
in the first place is that I felt both intuitively and logically the potential of
the full stack JavaScript. The one language to rule the whole stack across
all the layers. Logically I understood the code reuse, expressiveness, and
performance advantages of Node.js and the ever-increasing importance
of front-end development with MVC-like frameworks such as Backbone.
Intuitively, I just freaking fell in love with JavaScript both on the browser
and on the server.
Yes, I used JavaScript for many years but it was more pain than fun.
Not anymore. I was able to get a sense of what’s going on at the front end
while at the same time getting all the power and flexibility on the server.
My brain started to think 5, maybe 10 times faster than before because I

xv
Preface

started to remember all the obscure methods from Array or String objects.
I stopped having Mozilla Developer Network or Google open next to my
code editor. And what a relief when you don’t need to wait for the compiler
each time that you want to test something really quickly.
The airline crew announced my boarding. I need to get on the plane,
but I hope this easy, beginner-friendly manual will open the world of
full stack JavaScript and cloud computing. Jump on board this amazing
technology with me.

xvi
Introduction
The kind of programming that C provides will probably
remain similar absolutely or slowly decline in usage, but rela-
tively, JavaScript or its variants, or XML, will continue to
become more central.
— Dennis Ritchie

In this introduction, we cover:

• Reasons behind full stack JavaScript development in


general and for the writing of this book

• What to expect and what not to expect, and what are


the prerequisites

• Suggestions on how to use the book and examples

• Explanation of the book’s notation format

Full Stack JavaScript is a hands-on book that introduces you to


rapid software prototyping using the latest cutting-edge web and mobile
technologies including Node.js, MongoDB, Twitter Bootstrap, LESS,
jQuery, Parse.com, Heroku, and others.

Why This Book?


This book was borne out of frustration. I have been in software engineering for
many years, and when I started learning Node.js and Backbone.js, I learned
the hard way that their official documentation and the Internet lack good
quick start guides and examples. Needless to say, it was virtually impossible to
find all of the tutorials for JS-related modern technologies in one place.

xvii
Introduction

The best way to learn is to do, right? Therefore, I used the approach
of small, simple examples (that is, quick start guides) to expose myself to
the new cool tech. After I was done with the basic apps, I needed some
references and organization. I started to write this manual mostly for
myself, so I could understand the concepts better and refer to the samples
later. Then StartupMonthly and I taught a few two-day intensive classes
on the same subject—helping experienced developers to jump-start
their careers with only-one-language development, that is, JavaScript.
The manual we used was updated and iterated many times based on the
feedback received. The end result is this book.

Why Go Full Stack JavaScript?


The reasons I love developing with full stack JavaScript, or as others call it
universal or isomorphic JavaScript, are numerous:

• Code reuse: I can share my libraries, templates, and


models between the browser and the server.

• No context switch: My brain learns and thinks faster,


leaving me more time to work on the actual tasks at
hand.

• Great ecosystem: npm!

• Vibrant community: They are approachable and eager


to help.

• Great masters: A treasure chest of knowledge and


best practices has accumulated through the years of
browser JavaScript.

• Tons of tutorials and good books: JavaScript is the


most popular language, hence more people are
writing about it.

xviii
Introduction

• No compilation: Development is faster with interpreted


platforms.

• Good performance: Node’s non-blocking I/O is fast.

• Evolving standard: EMCA is constantly pushing new


and better versions of JavaScript.

I’m sure I’ve missed a few points, but you got the idea. Whatever the
drawbacks of ES5 (the language most of us know as JavaScript) are, they
were fixed in ES6/ES2015 and newer versions. The future for JavaScript is
so bright we all will have to code with sunglasses on.

What to Expect
Full Stack JavaScript readers should expect a collection of quick start
guides, tutorials, and suggestions (for example, Git workflow). There is a lot
of coding and not much theory. All the theory we cover is directly related
to some of the practical aspects and is essential for better understanding of
technologies and specific approaches to dealing with them (for example,
JSONP and cross-domain calls).
In addition to coding examples, the book covers virtually all setup and
deployment step by step.
You’ll learn on the examples of the Message Board application
starting with front-end components. There are a few versions of these
applications, but by the end of the book we’ll put the front end and back
end together and deploy to the production environment. The Message
Board application contains all of the necessary components typical for a
basic web app, and building it will give you enough confidence to continue
developing on your own, apply for a job/promotion, or build a startup!

xix
Introduction

Who This Book Is For


The book is designed for advanced-beginner and intermediate-level web
and mobile developers: somebody who has been (or still is) an expert in
other languages like Ruby on Rails, PHP, Perl, Python, or/and Java. He/she
is the type of developer, who quickly wants to learn more about JavaScript
and Node.js-related techniques for building web and mobile application
prototypes. The target reader doesn’t have time to dig through voluminous
(or tiny, at the other extreme) official documentation. The goal of Full
Stack JavaScript is not to make an expert out of a reader, but to help him/
her to start building apps as soon as possible.
As the full title indicates, Full Stack JavaScript: Learn Backbone.js, Node.
js and MongoDB is about turning your idea into a functional prototype in
the form of a web or mobile application as fast as possible. This approach
adheres to the Lean Startup methodology; therefore, this book would be
more valuable to startup founders, but big companies’ employees will also
find it useful, especially if they plan to add new skills to their resumes.

What This Book Is Not


Full Stack JavaScript is neither a comprehensive book on several
frameworks, libraries, or technologies (or just a particular one), nor a
reference for all the tips and tricks of web development. Examples similar
to ones in this book might be publicly available online.
More importantly, if you’re not familiar with fundamental programming
concepts like loops, if/else statements, arrays, hashes, objects, and functions,
you should be aware that you won’t find them covered in Full Stack
JavaScript. Additionally, it would be challenging to follow the examples.
Many volumes of great books have been written on fundamental
topics — the list of such resources is at the end of the book in the chapter
“Further Reading.” The purpose of Full Stack JavaScript is to give agile
tools without replicating theory of programming and computer science.

xx
Introduction

Prerequisites
I recommend the following prerequisites to get the full advantage of the
examples and materials covered in this book:

• Knowledge of fundamental programming concepts


such as objects, functions, data structures (arrays,
hashes), loops (for, while), and conditions (if/else,
switch)

• Basic web development skills including, but not limited


to, HTML and CSS

• Using macOS or UNIX/Linux systems for this book’s


examples (and for web development in general),
although it’s still possible to hack your way on a
Windows-based system

• Access to the Internet

• 5-20 hours of time

• A credit/debit card, which is required by some cloud


services even for free accounts

How to Use the Book


The digital version of this book comes in two formats:

1. PDF: Suited for printing; opens in Adobe Reader,


Mac OS X Preview, iOS apps, and other PDF viewers.
2. mobi: Suited for Kindles of all generations as well
as desktop and mobile Amazon Kindle apps and
Amazon Cloud Reader; to copy to devices use
Whispernet or a USB cable, or e-mail it to yourself.

xxi
Introduction

Links to web resources are provided throughout the book. In the


e-book version, the table of contents has local hyperlinks that allow
you to jump to any part or chapter of the book. This is very useful for
referring to certain parts of content later; for example, if you want to
look up how to deploy to Heroku, you can quickly jump to the needed
commands.
I encourage you to take notes and highlight text as you read it
studiously. It will improve your retention of the material.
There is a summary in the beginning of each chapter describing in
a few short sentences what examples and topics the particular chapter
covers.
Each project comes with a YouTube screencast video. I recommend
watching the videos to improve your comprehension. You can watch
the videos first or read the text first. The videos are supplemental, so
it’s not a big deal if you are reading the digital book offline or the print
book and don’t have the ability to watch the video. The text covers
everything in the videos. The reason I recorded the screencasts is
because people learn differently; some prefer text and others videos.
This way, you can take advantage of both media as well as see certain
development steps in action.
For faster navigation between parts, chapters, and sections of the book,
please use the book’s navigation pane, which is based on the Table of
Contents (the screenshot is below).

xxii
Introduction

The Table of Contents pane in the Mac OS X Preview app

E xamples
All of the source code for examples used in this book is available in the
book itself for the most part, as well as at the book’s Apress.com product
page (www.apress.com/9781484237175) and in a public GitHub
repository (https://github.com/azat-co/fullstack-javascript).
You can also download files as a ZIP archive or use Git to pull them. More

xxiii
Introduction

on how to install and use Git will be covered later in the book. The source
code files, folder structure, and deployment files should work locally and/
or remotely on PaaS solutions—that is, Windows Azure and Heroku—with
minor or no modifications.
Source code that is in the book is technically limited by the platform
to the width of about 70 characters. I tried my best to preserve the best
JavaScript and HTML formatting styles, but from time to time you might
see backslashes (\). There is nothing wrong with the code. Backslashes are
line escape characters, and if you copy-paste the code into the editor, the
example should work just fine. Please note that code in GitHub and in the
book might differ in formatting.
Last, let me (and others) know if you spot any bugs, by submitting
an issue to GitHub! Please, don’t send me bug reports in an e-mail,
because posting to a public forum like GH Issue will help others, prevent
duplicates, and keep everything organized.

N
 otation
This is what source code blocks look like:

var object = {};


object.name = "Bob";

Terminal commands have a similar look but start with a dollar sign:

$ git push origin heroku


$ cd /etc/
$ ls

Inline file names, path/folder names, quotes, and special words/names


are italicized, while command names (e.g., mongod and emphasized
words, such as Note, are bold.

xxiv
Introduction

Terms
For the purposes of this book, we’re using some terms interchangeably.
Depending on the context, they might not mean exactly the same thing.
For example, function = method = call, attribute = property = member =
key, value = variable, object = hash = class, list = array, framework = library
= module.
Additionally, “full stack” is listed as “fullstack” within code snippets.

xxv
PART I

Quick Start
CHAPTER 1

Basics
I think everyone should learn how to program a computer,
because it teaches you how to think. I view computer science
as a liberal art, something everyone should learn to do.
—Steve Jobs

In this chapter, we’ll cover these topics:

• Overview of HTML, CSS, and JavaScript syntaxes

• Brief introduction to Agile methodology

• Advantages of cloud computing, Node.js, and


MongoDB

• Descriptions of HTTP requests/responses and RESTful


API concepts

In this chapter we will brush up on the fundamental concepts before


moving forward. If you are an experienced web developer, then feel free
to skip this chapter. If you are new to web development, then pay extra
attention. Why? Maybe you have heard and are familiar with some terms,
but wonder what they actually mean. Another good reason is that this
chapter will cover the RESTful API in a very beginner-friendly manner. REST
is used in virtually all modern web architectures, and we’ll use it in the book
a lot. There is one last reason: You’ll look smart at a cocktail party or in front
of your colleagues and your boss by acing the hodpodge of web acronyms.

© Azat Mardan 2018 3


A. Mardan, Full Stack JavaScript, https://doi.org/10.1007/978-1-4842-3718-2_1
Chapter 1 Basics

Front-End Definitions
Front end is a term for browser applications. A browser is called a client
because in networking we use client-server communication. Users interact
with a client to make requests to a server, which sends back responses.
Thus frontend refers to browser or client applications. A client can be a
mobile application as well.
Very rarely in some conversations (by some rather old-school Java
architects), “front end” is used to define server applications. This is very
confusing. The only excuse I can make for this usage is that these server
apps are facing the browser requests first rather than some other server
applications. Or, depending on the context, these server applications act as
static web servers to the browser application. To have everything clear and
precise, for this book we assume that when we mention front end it is the
browser applications and their code.
Front-end development, or front-end web development, implies
the usage of various technologies. Each of them individually is not too
complex, but the sheer number of them makes beginners timid. For
example, technologies used include Cascading Style Sheets (CSS),
Hypertext Markup Language (HTML), Extensible Markup Language
(XML), JavaScript (JS), JavaScript Object Notation (JSON), Uniform
Resource Identifier (URI), Hypertext Transfer Protocol (HTTP), Secure
Sockets Layer (SSL), Transport Layer Security (TLS), Transmission Control
Protocol/Internet Protocol (TCP/IP), Internet Relay Chat (IRC), Remote
Procedure Call (RPC), GraphQL, ES, and many other technologies (my
next books will be called Swimming in Acronym Soup).
In addition to the low-level technologies, there are numerous
frameworks, tools, and libraries; for example, React, jQuery, ­Backbone.js,
Angular.js, Webpack, Grunt, and so on. Please don’t confuse front-end
frameworks with back-end frameworks: The front-end frameworks run on
the browser whereas the back-end ones run on the server.

4
Chapter 1 Basics

To build a web application developers have to have multiple things. In


a nutshell, front-end web development consists of these components:

1. HTML or templates that compile to HTML

2. Stylesheets to make HTML pretty

3. JavaScript to add interactivity or some business logic


to the browser app

4. Some hosting (AWS, Apache, Heroku, etc.)

5. Build scripts to prepare code, manage


dependencies, and do pretty much anything that’s
needed

6. Logic to connect to the server (typically via XHR


requests and RESTful API)

Now you know what a job that has the title of front-end developer
entails. The great payback to mastering this hodgepodge is the ability to
express your creativity by building beautiful and useful apps.
Before we start building, let’s cover a bird’s-eye view of the web request
cycle.

Web Request Cycle


This section is important for someone very new to the web development.
The whole World Wide Web or the Internet is about communication
between clients and servers. This communication happens by sending
requests and receiving responses. Typically browsers (the most popular
web clients) send requests to servers. Behind the scenes, servers send their
own requests to other servers. Those requests are similar to the browser
requests. The language of requests and responses is HTTP(S). Let’s explore
the browser request in more details.

5
Chapter 1 Basics

The browser request consists of the following steps:

1. A user types a URL or follows a link in his or her


browser (also called the client).

2. The browser makes an HTTP request to the server.

3. The server processes the request, and if there are


any parameters in a query string or body of the
request, it takes them into account.

4. The server updates, gets, and transforms data in the


database.

5. The server responds with an HTTP response


containing data in HTML, JSON, or other formats.

6. The browser receives the HTTP response.

7. The browser renders an HTTP response to the user in


HTML or any other format (e.g., JPEG, XML, JSON).

Mobile applications act in the same manner as regular web sites, only
instead of a browser there is a native app. Mobile apps (native or HTML5) are
just another type of client. Other minor differences between mobile and web
include data transfer limitation due to carrier bandwidth, smaller screens,
and the more efficient use of local storage. Most likely you, my reader, are
a web developer aspiring to use your web chops in mobile. With JavaScript
and HTML5 it’s possible, so it’s worth covering mobile development closer.

Mobile Development
Is mobile going to overtake web and desktop platforms? Maybe, but it’s
around 2020 and the web traffic is still around 50%. Moreover, the mobile
development development field is still somewhat hard and slow compared
to the web one. That’s good if you are a native mobile developer, but most of

6
Chapter 1 Basics

us are not. There’s a bigger gap in talent compared to web. The gap is closing.
With React Native, you can write once in JavaScript and reuse code on iOS and
Android. You can build Windows and macOS desktop apps with JavaScript
using Electron. There are other approaches to mobile and desktop that
leverage JavaScript as well.
These are the approaches to mobile development, each with its own
advantages and disadvantages:

1. Native: Native iOS, Android, Blackberry apps built


Objective-C, Swift, or Java.

2. Abstracted native: Native apps built with JavaScript,


React Native (https://facebook.github.io/
react-native), NativeScript, Appcelerator
(https://www.appcelerator.com), Xamarin,
(https://xamarin.com), Smartface (https://
www.smartface.io), or similar tools, and then
compiled into native Objective-C or Java.

3. Responsive: Mobile websites tailored for smaller


screens with responsive design, CSS frameworks
like Bootstrap (https://twitter.github.
io/bootstrap) or Foundation (https://
foundation.zurb.com), regular CSS, or different
templates. You might use some JavaScript
frameworks for the development like Backbone.js,
Angular.js, Ember.js, or React.js.

4. Hybrid: HTML5 apps which consist of HTML, CSS,


and JavaScript, and are usually built with frameworks
like Sencha Touch (https://www.sencha.com/
products/touch), Trigger.io (https://trigger.
io), or Ionic (https://ionicframework.com)

7
Exploring the Variety of Random
Documents with Different Content
VIJFDE HOOFDSTUK
EEN BRIEF VAN HUIS

Mejufvrouw L. Van Wageningen. Adres:


den WelEd. Heer Oristorio, enz., enz.

Liefste Lina!

Wel mijn kind, wat waren wij gelukkig toen wij heden morgen de
tijding ontvingen van uw goede aankomst in Oost-Indië! Richard is
den ganschen dag zóo wild geweest van vreugde dat er geen huis
met hem te houden was, Ella Salvita was te opgewonden om te
ontbijten, zelfs om mij suiker in mijn thee te geven, nu ik beken je
ronduit dat ik het niet bemerkt had vóor dat zij zelve het zag, en mij
lachend verweet dat ik even ongeduldig en zenuwachtig was als zij!
Je oude poes begreep niets van de consternatie, maar Bijoux scheen
je ganschen brief met ons te lezen, en deelde in de vreugde alsof hij
tot de familie behoorde. Mietje alleen kwam vrij nuchter uit den
hoek met haar: »Och! heetje! Is de juffer nou in dat verre land! Wel,
wel, ’t is wat te zeggen!” En dan beweren de geleerden dat Mietje
meer ziel heeft dan Bijoux. ’t Is mogelijk, maar ik geloof het niet. En
indien het zóo is, welnu dan acht ik er den hond des te hooger om,
daar hij beter gebruik van de zijne maakt dan zij van de hare.

En nu heb ik je wat nieuws mee te deelen, namelijk dat ik je wijzen


raad gevolgd en Ella ten huwelijk gevraagd heb. Zij was in deze
omstandigheid weer eenvoudig [42]groot, zooals zij in alle anderen
geweest is.—»Neen,” was haar eerste woord. »Ik ben de vrouw niet
die geluk in een familie brengen kan.”—»Wie kan die vrouw zijn,
indien gij haar niet zijt?” vroeg ik haar. »Waar is verstand en ziel en
wil vereenigd als in u? Waar liefde tot een hoogeren graad van
volmaaktheid opgevoerd dan in de zelfverloochenende grootheid die
de grondtrek van uw karakter uitmaakt.”

Zij zag mij aan, met haar groote dankbare oogen en schudde
weemoedig het hoofd, terwijl zij zacht en ferm zeide: »Neen,
ritmeester, gij hebt kinderen, voor wie gij den heiligen moedernaam
zuiver en onbevlekt bewaren moet.…. Een actrice vernedert de
kinderen die haar »moeder” noemen, verlaagt h e m die onder zijn
naam de minachting tracht te verbergen, die aan den hare
verbonden is.… Spreek nooit meer van een huwelijk. Laat mij bij u
blijven en gelukkig zijn en bekommer u niet verder over een leven
dat, God geve het, niet lang meer duren zal.”

Zij glimlachte, en verliet de kamer met een kalmte die ieder ander
dan mij, had doen denken dat zij ongevoelig was.

Ik oogde haar na toen zij den gang doorging, den trap op, in hare
kamer.… en toen alles stil was, volgde ik haar.

Ik vond haar op de sofa, met het gelaat in de handen, bitter


schreiende. Ik had de deur zóo zacht geopend dat zij mij niet had
hooren inkomen en dat ik naast haar zat eer zij het wist. »Ella,”
sprak ik nauw hoorbaar. »Kom, [43]wisch die tranen weg en laat ons
openhartig samen spreken.” Zij zag mij een oogenblik ontsteld aan,
liet toen het hoofd op mijn schouder zinken en snikte zenuwachtig
zonder een woord te kunnen uiten. Toen zij eindelijk tot bedaren
was gekomen en haar hoofd half lachend op had gericht met de
woorden: »Laat ons nu over iets anders spreken,” gaf ik haar uw
brief van de Kaap de Goede Hoop, en liet ik haar zelve lezen wat gij
omtrent een huwelijk tusschen haar en mij geschreven hadt.

Toen zij gelezen had, gaf zij mij met bevende hand den brief terug.

»Verlangt gij l i e f d e , ritmeester?” vroeg zij aarzelend.


»Neen. Ik verlang van u niet meer dan een jonge vrouw kan geven
aan een man van mijn leeftijd: achting, welwillendheid, vriendschap.
—” Zij zeide niets, opende een schrijfportefeuille, kreeg er een paar
oude brieven uit en overhandigde mij die met de woorden: »Hier is
mijn l i e f d e .—De vrouw aan wie deze brieven gericht waren is
dood, haar zuster zond ze mij terug, toen zij gestorven was, en als
de weemoedige herinnering aan lang vervlogen gouden droomen,
heb ik ze bewaard, niet denkende dat zij mij ooit te pas zouden
komen.—Lees ze en verscheur ze dan—mijn verleden is dáar.—Later
zullen wij over de toekomst spreken.”

Ik was gereed de brieven terstond te verscheuren en zeide haar dat


ik haar verleden als het mijne aannam, zonder onderzoek en zonder
twijfel; maar zij smeekte mij zoo dringend aan haar verzoek te
voldoen, dat ik gehoorzaamde en haar niet weerzag vóor etenstijd.
[44]

Wanneer gij deze letteren ontvangt, zal Ella mijne vrouw zijn, en dan
mijn kind zult gij een moeder hebben, op wie gij trotsch kunt
wezen.….….

[Inhoud]
ZESDE HOOFDSTUK
LOUISE VAN AMERONGEN
Het was in het midden van den goeden moesson. De zon wierp hare
stralen loodrecht op de huizen, waarvan de daken gloeiden en de
witgekalkte muren verblindend schitterden, terwijl de jalousieën
zorgvuldig gesloten waren en niemand zich meer in de galerijen
bevond. Ook de straten waren bijna geheel verlaten, slechts nu en
dan deed zich nog het rateltje van den K l o n t o n g 1 hooren, of het
gekraak van het bamboezen juk van den k o e l i 2 die, gebogen
onder zijn zwaren last, zijn weg vervolgen moest, terwijl alles rust en
uitputting ademde. Zelfs de vrouwen in de w a r o n g s 3 sliepen bij
hare n a s s i e 4 of k w e e - k w e e , 5 en de wisselaarsters op de
hoeken der straten hadden slechts eenige duiten vóor [45]zich liggen
om des te rustiger onder den half gescheurden p a j o n g 6 op de
kleine gevlochten t i k a r 7 te kunnen voortdommelen, gedurende de
weinige uren dat de groote warmte alles, tot zelfs het geld, bijna
vergeten deed.

’t Is nog te vroeg, maar wacht even, en wij zullen met de


ondergaande zon in deze schijnbaar uitgestorven stad het lachend
Samarang herkennen. Dan zullen wij alle huizen geopend zien, alle
wegen bezocht vinden, dan.… maar wacht nog even, het is nauwlijks
drie uur geslagen en de europeesche bevolking is nog grootendeels
in rust.

In den tuin, vóor een smaakvolle villa aan den Bodjongschen weg
loopt een jonge slavin, in haar kort wit baadjoe en rood geruiten
sarong, die met een gouden band om het middel wordt
vastgehouden, onophoudelijk van het eene bloembed naar het
andere. Zij knipt de schoonste knoppen af, plukt de geurigste rozen,
maar schudt nog steeds ontevreden het hoofd, alsof zij hetgeen zij
zocht, niet vinden kon. Eindelijk keert zij schoorvoetend naar huis
terug.

»Wat zal Nonna 8 boos zijn. Geen enkele witte roos van daag!” denkt
zij bij zichzelve en nauw hoorbaar sluipt zij een groote kamer
binnen, waar zij de bloemen in een blauw glazen kommetje op een
smaakvolle toilettafel plaatst.

»Hoe laat Alima?” roept een zachte stem uit het [46]groote ledikant,
waarvan de dunne neteldoeksche gordijnen langzaam door een fijn
wit handje op zijde worden geschoven.

»Bij vieren, Nonna.”

»Bij vieren! gauw de thee! Mijn hemel! Hoe kom ik nog klaar! Gooi
de jalousieën open! Roep Rosa! Kap mij! Raap mijn boek op! Geef
mijn kousen! Laat zien de bloemen! Gauw! Gauw! Ik heb haast!
Rosa! Rosa!”

Alima raapte dood bedaard, eerst het boek op, dat hare jeugdige
meesteres in haar drift uit bed had laten vallen, schoof toen een
grooten rotangstoel voor den toiletspiegel en opende eindelijk de
jalousieën, om daarna achtereenvolgens alle verdere bevelen ten
uitvoer te brengen, terwijl Louise van Amerongen met haar boek op
den grooten stoel neerviel en Eugène Sue’s »Orgueil” half liggend
vervolgde, zooals zij die een uur te voren half slapend begonnen
was.

Toch was Louise niet lui, noch heerschzuchtig, noch wispelturig,


maar zij was verwend. Zij was de eenige dochter van een schatrijken
koopman, de oogappel, de afgod, de geheele toekomst harer
ouders, die haar lief hadden en bedierven met een verblindheid
welke alle perken te buiten ging. Tusschenbeide had het mevrouw
Van Amerongen wel eens gehinderd dat hare dochter zoo langzaam
in hare bewegingen, zoo kortaf in hare antwoorden, wezen kon;
maar mevrouw Van Amerongen was een Europeesche vrouw, terwijl
haar dochter geboren en opgevoed was in Indië, waar
onverschilligheid en opvliegendheid elkander steeds de eerste plaats
in het hart der meeste vrouwen [47]betwisten; zij begreep dus dat zij
hier met een kwaal te worstelen had, waarvan haar kind niet dan
met de grootste moeite te genezen zou zijn. Buitendien was Louise
rijk en bevallig genoeg dat men haar zulke kleine gebreken vergeven
kon. Heeft niet ieder mensch het een of ander in gewoonte of
manieren dat wel anders wezen mocht? En verder werd er niet aan
de verbetering van de oogappel gedacht.

Louise was nauwelijks vijftien jaar oud, maar zij was groot voor haar
leeftijd en geheel ontwikkeld; daarbij was zij schoon met haar
fluweel zwarte oogen, haar golvend haar en hare schitterend witte
tanden, haar slanke leest en haar kleine welgevormde handen en
voeten. Ook was er iets vreemds, iets aantrekkelijks in hare bevallige
ronde bewegingen, in haar statigen langzamen gang, terwijl haar
fiere houding, gevoegd bij haar zachte welluidende stem, aan haar
geheele persoon iets boeiends en meesleepends gaven.

En het hart?—Het hart was goed en sloeg voor al wat groot en edel
is. Ook het hoofd was goed, maar ’t was niet goed bestuurd
geworden, en hierdoor werd dáar waar het scherpe oordeel van het
k i n d tekort schoot, helaas! maar al te dikwijls de koude rede van
den »gedésillusionneerden” mensch geloofd.

Alima kwam eindelijk terug met een kopje koude thee en een paar
schoteltjes kwee-kwee. Rosa, een meisje van een jaar of dertien,
volgde haar, plaatste zich zwijgend tegen den muur en wachtte.

»Waarop wacht gij?” vroeg Louise. [48]

»Ik ben bij nonna Van den Berg geweest, nonna.”


»En?”

»Nonna Van den Berg zal tegen half zes te paard hier zijn.”

»Goed.”

»Toewan ketjil 9 laat vragen of hij de nonnas vergezellen mag?”

»Hm—m,” toestemmend geluid.

»Moet ik antwoord zenden, nonna?”

»Neen, kap mij.”

Rosa maakte een zestal breede vlechten van het weelderige, zwarte
haar en schikte ze in sierlijke lussen om het fraaie kopje harer
meesteres.

»Alima, krijg mijn amazone uit de kast, en al wat ik verder noodig


heb, leg alles op bed bij elkaar.”

De slavin liep eenige keeren de kamer op en neer, haalde hier het


rijkleed, daar den hoed, ginds de handschoenen en plaatste zich,
toen alles gereed lag, naast Rosa, achter den stoel harer meesteres
om op nieuwe bevelen te wachten.

Louise echter was geheel in l ’ O r g u e i l verdiept, en hoorde of zag


niets van hetgeen er om haar henen voor viel.

De pendule sloeg weer éen, daar werd zij wakker.

»Ja! Allah! half vijf!”

L ’ O r g u e i l ging op den grond, de koekjes moesten


[49]weg, de thee stortte over het blad, alles ging het onderste boven
om nonna spoedig in de kleeren te helpen … Eindelijk was zij gereed,
en met een lichten blos van het reppen, trad zij in haar sierlijk
rijkleed den hoogen stoep af, onderaan welken Henri van den Berg,
de broeder harer vriendin, gereed stond om haar bij het te paard
stijgen behulpzaam te zijn.

»Waar blijft Marie?” vroeg zij lachend.

»Zij zal volgen met papa en met Willem Nieland, dien wij juist tegen
kwamen toen wij het hek uit reden.” En hij zag haar aan alsof hij
voor haar antwoord vreesde.

»Wij zullen hen te gemoet gaan,” sprak het meisje spotachtig. Henri
boog zwijgend en reikte haar de hand tot opstijgen.

Wat was de jonge lachende Louise schoon, toen hare donkere oogen
van hoop en leven schitterden en hare slanke buigzame gestalte zoo
sierlijk uitkwam op den fieren Arabischen Isabel die, trotsch op zijn
schoonen last, het edel hoofd nog hooger ophief en in vollen galop
het hek uitvloog.

Louise’s ouders oogden haar na en konden den glimlach niet


bedwingen, die zoo duidelijk zeide hoe zij hun eenig kind
bewonderden en liefhadden, met al den trots hunner ziel.

»Henri verraadt zich toch gedurig,” sprak mijnheer Van Amerongen.

»Louise houdt zich goed,” antwoordde mevrouw.

»Zij zal het niet opmerken.”

»O, haar ontgaat niets!” [50]

»Henri is een beste, brave jongen, maar toch voor Louise …”


»O, Louise kan wel betere partijen doen.”

»Dat geloof ik!”

»Louise ik begrijp u niet!” sprak Henri.

»Dat verlang ik ook niet.”

»Maar … Kom, antwoord mij eens wat duidelijker … Zeg mij, bid ik
u …”

»Éens Henri, maar éens vooral, hoor! Ik houd niet van herhalen, dat
weet gij. Gij wilt weten of ik u lief heb, niet waar?”

»Ja,” antwoordde hij nauw hoorbaar.

»Welnu, ik heb er velen lief als u.”

»En acht gij mij?” vroeg hij verder.

»Meer dan alle anderen te zamen.”

»En toch …”

»Uw vrouw, nooit, dat weet gij.”

»Maar Louise!”

»Geen woord meer.”

»Maar welke toekomst droomt gij u dan? Wat verlangt gij …”

»Ik denk aan geen toekomst en ik verlang niets. Niets dan vrij te
blijven en mijn rechten op mij zelve te behouden.”
»Altijd?”

Louise wendde lachend het hoofd van hem af.

»Zijn die rechten op u zelve u zoo dierbaar, dat gij ze levenslang


zoudt wenschen te behouden?” [51]

»Oude jonge juffrouw!” riep het meisje als verschrikt, en zij lachte
zóo hartelijk dat Henri onwillekeurig met haar mede deed. »Neen,
neen, dat nooit!”

»Wat dan?”

»Niets.”

»Louise, Louise, waar …”

»Ik ben jong en gelukkig Henri, waarom …”

»Gij hebt gelijk. Gij zijt jong en gelukkig! Geniet! Geniet zoo lang het
u mogelijk zal zijn; blijf vroolijk en onbezorgd voortleven in de
weelde en in de liefde die u omringen en droom u een toekomst zóo
schoon en zóo heerlijk als uw fantastische verbeelding ze u slechts
voor kan spiegelen.”

»En in de werkelijkheid?”

»Zult gij mogelijk een beter man gelukkig kunnen maken, een edeler
mensch uw liefde kunnen schenken dan ik ben.”

»Neen, dat nooit!”

Die woorden waren haar ontvallen, want nauwlijks had zij ze


gesproken of een hoog rood steeg haar tot aan het voorhoofd, en,
zich snel voorover buigende, liet zij haar paard den vrijen teugel en
rende zij voort tot dat zij mijnheer Van den Berg met Marie en
Willem Nieland ontmoette. [52]

Chineesche marschkramer. ↑
1
Lastdrager. ↑
2
Een klein dak van bladeren op vier bamboezen stijltjes. ↑
3
Gekookte rijst; ongekookte noemt men b r a s , en in de halmen heet
4
zij paddie. ↑
Snoeperijen, gebak. ↑
5
Groote e n - c a s van bladeren of geolied papier. ↑
6
Matje. ↑
7
Juffrouw. ↑
8
Jonge mijnheer. ↑
9

[Inhoud]
ZEVENDE HOOFDSTUK
EEN BAL
In de dagen der verpachting telde Samarang de meeste feesten. De
resident, de kolonel, nog een paar hooggeplaatste personen en
eenige rijke partikulieren waren er op gesteld de vreemde residenten
beleefdheden te bewijzen en hadden dus reeds van te voren met
elkander overlegd, over welke dagen ieder van hen te beschikken
zou hebben.

Wat al vreugde voor de jonge meisjes, die weder haar balkleederen


in gereedheid konden brengen en menigen vroolijken avond in het
vooruitzicht hadden. Maar welk een vreugde voor Louise van
Amerongen vooral, die weder zou schitteren en uitblinken boven
allen en reeds vooraf verzekerd kon wezen van nieuwe en
onafgebroken triomfen!

Wat was zij schoon toen zij ’t open rijtuig uitsprong en het helder
licht der dammers haar vriendelijk gelaat bescheen! Toen het vol
orkest haar met de groote trom aan ’t hoofd, begroette, en zij
lachend haar net geganteerde hand aan Albert van den Hove reikte,
om op zijn arm geleund de lange galerijen van het residentiegebouw
te doorloopen, eerst haar opwachting bij de gastvrouw te maken en
vervolgens haar plaats in te nemen aan het lagere einde der zaal,
waar zij terstond door een aantal heeren omringd werd, die elkander
verdrongen voor een [53]dans, een lach, een blik van de »Roos van
Samarang”.

Wat was zij schoon toen ze eindelijk drong door den dichten drom
van aanbidders die haar den weg versperde, en licht en vlug de wals
begon, welke zij volhield, van den eenen danser naar den anderen
overgaande, tot dat de muziek verstomd was en het laatste paar van
vermoeidheid uitgeput tot staan was gekomen.

Hoe velen hadden haar opgemerkt, hoe velen hadden haar


nageoogd en door hoe velen was zij weder bewonderd of benijd
geworden?

Zij wist het niet; maar het kon haar ook niet schelen. Zij die gewoon
was opgemerkt te worden, zag niet meer dat zij nageoogd,
bewonderd en benijd werd. Het wufte kind van het oogenblik bleef
koud voor de lofuitingen der wereld, terwijl haar hart schier
hoorbaar klopte en haar oogen schitterden van geluk bij het denken
aan een tweede wals!

Lach maar kind! De ware wijsheid is geluk. De wereld biedt tranen


genoeg en zorgen in overvloed aan den rijpen leeftijd; lach gij maar
voort zoolang gij lachen kunt. De vroolijkheid is het schoonste
sieraad der jeugd. Geniet zoolang gij slechts kunt, dans voort, en
volg de inspraak van uw hart, zoolang die uit kinderlijken eenvoud
en oprechtheid voortspruit; wees wispelturig zelfs, als gij wilt … de
wispelturigheid op uw jaren is geen gebrek, wanneer zij met
goedhartigheid gepaard gaat.

»Neen, ik blijf zitten,” zei ze.

»Maar Louise, gij die nooit wilt blijven zitten!”

»Al zou het dan ook enkel voor de variatie wezen.” [54]

»Een quadrille is toch niet vermoeiend, die kunt gij even goed mee
doen als …”

»Vermoeiend! En wie spreekt daarvan? Ik ben nooit vermoeid!”

»Nu, kom dan mede?”


»Neen.”

»Maar Louise!”

»Neen.”

»Gij zijt al zeer kort af, van avond.”

»Ik ben ook heel boos op u.”

»Op mij?”

»Ja.”

»Maar waarom dan? Wat heb ik u gedaan?”

»Mij? O! mij niets. Mij kunt gij niets doen! Maar mijn vriendin hebt
gij beleedigd en dat vergeef ik u niet licht.”

»O ho! U w v r i e n d i n ? Die zwarte Mathilde, met wie ik niet


dansen wil omdat zij te klein en te mager en te leelijk is.… Nu, dit
kunt gij mij toch niet kwalijk nemen, hé?”

»Hoor eens Willem, zij mag zoo leelijk zijn als gij wilt, dat kan ze niet
helpen, het arme schaap, maar ze is goed en dat is genoeg.”

»Maar dat is niet genoeg voor mij, om voor mijn plezier met haar te
dansen.”

»Dat behoeft ook niet, dans maar, en ik zal u niet vragen of gij het
voor uw plezier gedaan hebt.”

»Neen,” riep Willem, op zijn beurt kort af en naar de leelijke


Mathilde omziende, ten einde een lach te verbergen. [55]

»Wilt gij niet?”


»Neen.”

»Goed.”

Willem bleef nog eenige oogenblikken zwijgend staan wachten,


terwijl Louise met haar waaier speelde.

»De dans begint.”

»Goed.”

»Bedenkt gij u niet?”

»Neen.”

»Dan blijf ik hier bij u zitten.”

»Hm.”

»Gij zult toch wel met mij willen spreken, hoop ik?”

»Neen.”

»Ook niet, wanneer ik met Mathilde gedanst zal hebben?”

»O! dan wil ik alles!”

»Dan krijg ik een dans?”

»Drie, als gij wilt!”

»Goed, maar ik zal ook niet behoeven te vragen of gij ze »voor uw


plezier” zult doen.”

Een gulle, ongedwongen lach was Louises eenig antwoord.


»Wie is zij, die ik daar zoo spotachtig zie lachen, schoon oud en jong
in de quadrille staat en zij alleen is blijven zitten?”

»Waar?.… Het is de Roos van Samarang, geloof ik! Juist zij is het!
Welke tinka (caprice) is dat nu weer?”

»Tinka?—Zou men haar gevraagd hebben, denkt gij?” [56]

»Haar gevraagd? Wel, wel resident, nu toont gij dat gij vreemdeling
zijt! Kent gij Louise van Amerongen nog niet?”

»Is zij Louise van Amerongen? De kleine coquette die alle luitenants
het hoofd op hol brengt?—Een aardig kopje! Ik zou mij waarachtig
weleens aan haar willen laten voorstellen.”

»Nu, kom maar mede.”

»Ja, maar is het niet wat gek, hè? een resident … Dàt zal haar
geheel ongenaakbaar maken.”

»Ta, ta, ta, wat al gebluf! Kom maar mee, van dien kant hebt gij
niets te vreezen.”

»Juffrouw Van Amerongen, mag ik de eer hebben u resident Stevens


van Langendijk voor te stellen!”

Louise boog even, bood de heeren een stoel aan, en zweeg, den
resident vragend aanziende, om hem te kennen te geven dat hij aan
het woord was.—Dit is een gewoonte, vrij algemeen op Java, waar
een dame bijna nooit het eerst het woord tot een heer zal richten.

»Wat hebt gij daar een lief toiletje aan, juffrouw Van Amerongen.”

Louise, met een beleefd lachje: »vindt u?”


»O ja, en dat beelderige coiffuurtje! Zoodra gij de zaal binnen
kwaamt, hebt gij mij getroffen.”

»Ja?”

De resident kuchte eens.

»Ik heb zooveel over u hooren spreken,” begon hij weder, »dat ik
mijnheer Vrede terstond verzocht heb mij aan u te presenteeren,
maar gij zijt den ganschen avond [57]zóo geëntoureerd geweest, dat
wij geen gelegenheid vinden konden om tot u door te dringen.”

»Hm!” met een lachje.

Hij kuchte weder.

»Verduiveld, hoe bête!” dacht hij bij zichzelven, zonder te letten op


de groote nonsense die hij zelf met zooveel emphase voordroeg.

»Woont gij reeds lang in dat prachtige huis aan den Bodjongschen
weg, juffrouw Van Amerongen?”

»Sedert drie jaar pas.”

»Gij gaat zeer veel uit, niet waar?”

»Ja, er wordt hier nog al eens gedanst.”

»En gij houdt niet van dansen, hè?”

»Ik? O, dol!”

»En gij zijt nu blijven zitten?”

»Dezen keer—ja.”
»Bij preferen … bij verkiezing natuurlijk, want …”

»Ja, resident.”

Zóo spraken zij nog eenige minuten, tot dat de quadrille geëindigd
was. Toen werd Louise weder van alle kanten door bewonderaars
omringd, terwijl de resident met zijn vriend naar zijn speeltafeltje
terugkeerde en, recht voldaan over zich zelven, een lange
redevoering hield over de domheid, nietigheid en kleingeestigheid
der vrouwen: »Zij zijn toch allen gelijk, of men er éen ziet of
honderd, er zit nooit iets bij.”

En wat antwoordde Louise, toen haar cavalier haar half lachend, half
verwijtend vroeg, »hoe de ongehuwde resident haar bevallen was?”
[58]

»Och, goed!”

»Dat meent gij niet.”

»Waarom?”

»Omdat gij het zóo niet zeggen zoudt, indien gij het meendet.”

»Maar wat wilt gij dan dat ik antwoorden zal, wanneer gij mij naar
iemand vraagt dien ik zoo even voor het eerst gezien heb?”

»Wel zeg mij hoe gij hem vindt, aangenaam of onaangenaam,


aardig of niet, verstandig of …”

»O neen, over zijn verstand althans kan ik niet oordeelen!”

»En waarom niet?”

»Omdat men een heer eenige malen met andere heeren ongestoord
moet hebben hooren spreken, om te weten of er wat bij zit of niet;
met ons dames zijn alle heeren dom.”

»O! dat zal ik mijn vriend terug vertellen!”

»De resident is uw vriend?”

»Ja juffrouw.”

»Goed.”

»Ik mag dus?”

»Och! waarom niet; het kan mij niet schelen.”

En zij danste weder voort, en sprak en lachte en was gelukkig als te


voren, zonder verder aan den resident te denken.

Nu kent gij Louise van Amerongen, wier schoonheid aller oogen


boeide, wier coquetterie aller tongen in beweging bracht.
Coquetterie! ’t Arme kind wist niet eens [59]wat dat uitheemsche
woord beteekende! Dat behoefde ook niet. Zij was jong en schoon
en rijk, en daarbij was zij vrij in hare bewegingen en ongedwongen
in haar gesprekken: wat is er meer noodig om een vrouw
c o q u e t t e te noemen?

Louise, het vroolijke, zorgelooze kind, kende haren bijnaam en


lachte er om, terwijl zij onschuldig met de harten harer aanbidders
speelde en hare nijdige v r i e n d i n n e n over haar wangunst
bespotte.

O, vrouwen! zoo gij wist hoe gij uzelve benadeelt door al dat
noodeloos geschimp, door dat geringschatten van al wat uw sfeer te
boven gaat! Zoo gij wist hoe bespottelijk gij uw eigen nietigheid
tentoonstelt, door de meerderheid van anderen onzinnig te
ontkennen, gij zoudt zwijgen, geloof ik, al ware het ook slechts uit
eigenbelang … Maar neen, gij zoudt niets, zoolang gij uw arme ziel
niet gereinigd hadt van de duizende, kleine, lage hartstochten die in
o n k u n d e hun oorsprong hebben en als égoïsme, haat en afgunst
het leven verpesten van uzelve zoowel, als van de onschuldige
wezens die het ongeluk hebben van door u opgemerkt te worden.
[60]

[Inhoud]
ACHTSTE HOOFDSTUK
HET BEZOEK VAN DEN RESIDENT
Den dag na het bal was Louise weder alleen in haar kamer. Ditmaal
sliep zij niet; zij lag in een dun wit morgengewaad op een rustbank
uitgestrekt en speelde met de donkere lokken die langs haar
schouders golfden en in dikke krullen tot op den vloer neder hingen.
Hare oogen staarden gedachteloos en haar lippen waren stijf op
elkander geperst, terwijl haar boek nog ongeopend naast haar lag.
Plotseling sprong zij uit hare half droomende, half wakende houding
op, een koortsachtige flikkering schitterde in haar somber oog en
een diepe zucht ontsnapte den geprangden boezem.

Toen wierp zij zich weder in de kussens en wachtte kalm en geduldig


tot dat Alima met de thee kwam om haar, als naar gewoonte, te
wekken en te helpen kleeden.

»Is het zoo goed, nonna?” vroeg de jonge slavin, toen het
weelderige haar gevlochten en opgemaakt was. »Vindt nonna de
bloemen frisch genoeg?”

»Bloemen! O neen, geen bloemen vandaag!”

Alima wierp de met zooveel zorg geschikte rozen ter zijde.

»Is het nu naar uw zin, nonna?”

»Hm—m.”

En zonder zelfs een blik in den spiegel te werpen, stond Louise op


en liet zij Alima ongestoord haar toilet voltooien [61]alsof het haar
niet schelen kon hoe zij er uit zou zien.
Voor dien avond had resident Stevens van Langendijk belet laten
vragen bij mijnheer en mevrouw Van Amerongen, en Louise, die
deze eer verbazend vervelend vond, had een rijtuig laten inspannen
om Marie van den Berg te halen, met wie zij den ganschen avond
half fluisterend zat te praten om den resident niet in zijn gesprekken
te stooren, die nu, m e t o p z e t , in het geheel niet dom of
onbeduidend waren.

»Zij is verduiveld mooi!” dacht de resident bij zichzelven, terwijl hij


zich uitsloofde om de aandacht van het jonge meisje op de een of
andere wijze tot zich te trekken. »Zij zou wel goed voldoen in het
groote residentiehuis—aan het hoofd van de tafel—naast den
Gouverneur-Generaal bij voorbeeld—als mijn vrouw: Louise Stevens
van Langendijk—dat klinkt nog zoo slecht niet. En een meisje met
fortuin … Enfin, daar kunnen wij altijd nog wel toe komen.—Eén
woord en ik heb haar!”

»Wat is hij leelijk!” waren bijna op hetzelfde oogenblik Louise’s


gedachten. »Zoo’n rood gezicht—en zulke grasgroene oogen, met
zulk lichtgeel haar! Net boeloe jagong!—Ik kan mij best begrijpen
dat hij niet getrouwd is.—Wie zou ook zoo’n man willen hebben!”

Eindelijk sloeg het elf uur en ging de resident naar huis. Ieder kreeg
een handje, Louise alleen werd met een stijve buiging afgescheept.

»Niet beleefd!” fluisterde zij Marie lachend in het oor, [62]terwijl zij
het hoofd van hem afwendde en zich, zonder verder over hem te
spreken, ter ruste begaf, tevreden over hare opzettelijke
onverschilligheid en hoogst voldaan over de halve onbeleefdheid van
den resident.

Vreemd vrouwelijk instinkt! Louise was gelukkig over den weinig


gunstigen indruk dien zij op den resident scheen gemaakt te
hebben, en toch beving haar een soort van huivering wanneer zij
aan die koude, stijve buiging dacht.

En waarom?

Zij wist het niet. Zij kon zich geen rekenschap geven van het vreemd
gevoel waarmede zij te worstelen had, telkens wanneer zij zijn naam
slechts hoorde. Toch had zij eigenlijk niets tegen den resident, en
kon zij geen enkele reden vinden om hem minder genegen te wezen
dan iederen anderen vreemdeling, met wien de omstandigheden
haar in kennis brachten.

»Ik ben bang voor dien man!” dacht zij bij zichzelve, en hoewel zij
zich moeite gaf hem te vergeten of haar kinderachtigen afkeer van
hem te overwinnen, toch was haar laatste gedachte telkens weder:

»Ik ben bang voor hem!” [63]

[Inhoud]
NEGENDE HOOFDSTUK
DE HUWELIJKSAANVRAAG
»Is nonna Louise t’huis?” vroeg Marie van den Berg, den volgenden
morgen reeds om half negen uit haar palankijn 1 stappende.

»De nonna is in hare kamer, nonna.”

»Goed. Gij kunt heengaan, Drono. Mijnheer Van Amerongen zal mij
van avond wel naar huis laten brengen.”

Drono reed weg en Marie begaf zich naar Louise’s kamer, waar zij
haar vriendin met loshangend haar, op een matje op den vloer vond
zitten, bezig met een kleinen zwarten aap in de kleeren harer pop te
steken.

»Wat doe je daar?” vroeg zij lachend. »Ja, kassian! Arm Keesje!
Wacht, ik zal je helpen, hier, hier is een speld.”

»Dank je. Och, Marie, je neemt niet kwalijk dat ik niet opsta.…”

»Ik kom bij je zitten. Wel mijn goed best Keesje! Hoe gaat het? Wat
ziet hij er uit, het stumpertje. Hier is zijn kleedje. Gedécolleteerd nog
al! En wat een mager, zwart, ruig halsje, zal daar uitkomen!”

»En die zevenmijls handjes en voetjes!”

»O! Wat is Keesje nu mooi! Ja, kassian! Wat houdt [64]hij zich stil!
Wat is hij deftig! Wat loopt hij trotsch! Net de vrouw van Pieter
Papelaya! hè?”

»Ja, ja, precies Kakamia Papelaya! maar toch zóo leelijk niet!”

En Kees kreeg op elke wang een zoen en een pisang 2 tot belooning.
De meisjes hadden dolle pret, en nauwlijks was de pisang op, of zij
grepen Keesje ieder bij een poot en begonnen een wandeling door
de achtergalerij.

»Wij moesten eigenlijk een wagentje hebben,” begon Marie, »dan


konden wij den tuin met hem rondrijden.”

»Een wagentje? Ja—wacht—wilt gij hem even vasthouden dan zal ik


den ouden mandewagen gaan zoeken, die moet hier of daar in de
bijgebouwen staan, geloof ik. De kinderen van den koetsier hebben
er laatst mee gespeeld.—Ha! daar zie ik Rosa! Rosa, haal den
mandewagen!”

»De mandewagen Nonna? Daar zijn de voorwielen af.”

»Dat is niets, haal hem maar.”

Een oogenblik later kwam Rosa met een ouden mandewagen


aangeloopen, dien zij zeer voorzichtig aan den vóorkant ophield om
hem niet verder te vernielen.

»Wel zóo gaat het goed!” riep Marie, verrukt over de twee
achterwielen, die nog vastzaten en ronddraaiden. »Als gij ons nu een
kussen kunt geven, dan zult gij Keesje eens deftig in zijn equipage
zien zitten.”

Rosa bracht een gehaakt canapé-kussen uit Louise’s [65]kamer,


Keesje werd er op gezet en zoo nam de toer een aanvang.—Kees liet
zich de pret geduldig welgevallen, zoo lang hij bijna geen beweging
gevoelde, maar toen de meisjes, dat langzaam loopen moede, het
op een draven begonnen te zetten zonder aan het ontbreken van de
voorwielen te denken, toen werd de arme Kees zoodanig heen en
weer geschokt dat hij uit pure wanhoop den wagen uitsprong en

You might also like