Web Development with Node and Express Leveraging the JavaScript Stack 2nd Edition Ethan Brown download
Web Development with Node and Express Leveraging the JavaScript Stack 2nd Edition Ethan Brown download
https://textbookfull.com/product/web-development-with-node-and-
express-leveraging-the-javascript-stack-2nd-edition-ethan-brown/
https://textbookfull.com/product/pro-mern-stack-full-stack-web-
app-development-with-mongo-express-react-and-node-2nd-edition-
vasan-subramanian/
https://textbookfull.com/product/pro-mern-stack-full-stack-web-
app-development-with-mongo-express-react-and-node-vasan-
subramanian/
https://textbookfull.com/product/pro-mern-stack-full-stack-web-
app-development-with-mongo-express-react-and-node-1st-edition-
vasan-subramanian-auth/
https://textbookfull.com/product/full-stack-react-projects-
modern-web-development-using-react-16-node-express-and-
mongodb-2nd-edition-shama-hoque/
Learning JavaScript 3rd Edition Ethan Brown
https://textbookfull.com/product/learning-javascript-3rd-edition-
ethan-brown/
https://textbookfull.com/product/pro-express-js-master-express-
js-the-node-js-framework-for-your-web-development-mardan-azat/
https://textbookfull.com/product/programming-web-applications-
with-node-express-and-pug-1st-edition-jorg-krause-auth/
https://textbookfull.com/product/full-stack-javascript-learn-
backbone-js-node-js-and-mongodb-mardan-azat/
1. Preface
2. 1. Introducing Express
a. Getting Node
b. Using the Terminal
c. Editors
d. npm
e. A Simple Web Server with Node
i. Hello World
ii. Event-Driven Programming
iii. Routing
iv. Serving Static Resources
f. Onward to Express
a. Scaffolding
b. The Meadowlark Travel Website
c. Initial Steps
e. npm Packages
f. Project Metadata
g. Node Modules
h. Conclusion
6. 5. Quality Assurance
a. The QA Plan
b. QA: Is It Worth It?
c. Logic Versus Presentation
d. The Types of Tests
e. Overview of QA Techniques
f. Installing and Configuring Jest
g. Unit Testing
i. Mocking
ii. Refactoring the Application for Testability
iii. Writing Our First Test
iv. Test Maintenance
v. Code Coverage
h. Integration Testing
i. Linting
j. Continuous Integration
k. Conclusion
i. Rendering Content
ii. Processing Forms
iii. Providing an API
k. Conclusion
e. Conclusion
9. 8. Form Handling
a. Externalizing Credentials
b. Cookies in Express
c. Examining Cookies
d. Sessions
i. Memory Stores
ii. Using Sessions
e. Using Sessions to Implement Flash Messages
f. What to Use Sessions For
g. Conclusion
a. Middleware Principles
b. Middleware Examples
c. Common Middleware
d. Third-Party Middleware
e. Conclusion
i. Sending Mail
ii. Sending Mail to Multiple Recipients
g. Better Options for Bulk Email
h. Sending HTML Email
i. Images in HTML Email
ii. Using Views to Send HTML Email
iii. Encapsulating Email Functionality
i. Conclusion
a. Execution Environments
b. Environment-Specific Configuration
c. Running Your Node Process
d. Scaling Your Website
f. Stress Testing
g. Conclusion
a. Filesystem Persistence
b. Cloud Persistence
c. Database Persistence
i. A Note on Performance
ii. Abstracting the Database Layer
iii. Setting Up MongoDB
iv. Mongoose
v. Database Connections with Mongoose
vi. Creating Schemas and Models
vii. Seeding Initial Data
viii. Retrieving Data
ix. Adding Data
x. PostgreSQL
xi. Adding Data
d. Using a Database for Session Storage
e. Conclusion
a. HTTPS
d. Conclusion
20. 19. Integrating with Third-Party APIs
a. Social Media
b. Geocoding
c. Weather Data
d. Conclusion
21. 20. Debugging
b. Conclusion
23. 22. Maintenance
25. Index
Web Development with
Node and Express
Leveraging the JavaScript Stack
SECOND EDITION
Ethan Brown
Web Development with Node and Express
by Ethan Brown
The views expressed in this work are those of the author, and do not
represent the publisher’s views. While the publisher and the author have
used good faith efforts to ensure that the information and instructions
contained in this work are accurate, the publisher and the author disclaim
all responsibility for errors or omissions, including without limitation
responsibility for damages resulting from the use of or reliance on this
work. Use of the information and instructions contained in this work is at
your own risk. If any code samples or other technology this work contains
or describes is subject to open source licenses or the intellectual property
rights of others, it is your responsibility to ensure that your use thereof
complies with such licenses and/or rights.
978-1-492-05351-4
[LSI]
Dedication
Then, of course, there are the programmers like me, who have been
around for a while. Like many programmers of my era, I started off with
assembler and BASIC and went through Pascal, C++, Perl, Java, PHP,
Ruby, C, C#, and JavaScript. At university, I was exposed to more niche
languages such as ML, LISP, and PROLOG. Many of these languages are
near and dear to my heart, but in none of these languages do I see so much
promise as I do in JavaScript. So I am also writing this book for
programmers like myself, who have a lot of experience and perhaps a
more philosophical outlook on specific technologies.
Most important, this book is for programmers who are excited. Excited
about the future of the internet and want to be part of it. Excited about
learning new things, new techniques, and new ways of looking at web
development. If, dear reader, you are not excited, I hope you will be by the
time you reach the end of this book….
Chapter 5 discusses testing and QA, and Chapter 6 covers some of Node’s
more important constructs and how they are extended and used by
Express. Chapter 7 covers templating (using Handlebars), which lays the
foundation of building useful websites with Express. Chapter 8 and
Chapter 9 cover cookies, sessions, and form handlers, rounding out the
things you need to know to build basic functional websites with Express.
Chapter 14 gets into the details of routing with Express (how URLs are
mapped to content), and Chapter 15 takes a diversion into writing APIs
with Express. Chapter 17 covers the details of serving static content, with
a focus on maximizing performance.
Chapter 16 takes what we’ve learned about Express and uses it to refactor
the running example as an SPA, with Express as the backend server
providing the API we created in Chapter 15.
Chapter 20 and Chapter 21 get you ready for the big day: your site launch.
They cover debugging, so you can root out any defects before launch, and
the process of going live. Chapter 22 talks about the next important (and
oft-neglected) phase: maintenance.
The book concludes with Chapter 23, which points you to additional
resources, should you want to further your education about Node and
Express, and where you can go to get help.
Example Website
Starting in Chapter 3, a running example will be used throughout the
book: the Meadowlark Travel website. I wrote the first edition just after
getting back from a trip to Lisbon, and I had travel on my mind, so the
example website I chose is for a fictional travel company in my home state
of Oregon (the Western Meadowlark is the state songbird of Oregon).
Meadowlark Travel allows travelers to connect to local “amateur tour
guides,” and it partners with companies offering bike and scooter rentals
and local tours, with a focus on ecotourism.
Italic
Indicates new terms, URLs, email addresses, filenames, and file
extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to
program elements such as variable or function names, databases, data
types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the
user.
Constant width italic
Shows text that should be replaced with user-supplied values or by
values determined by context.
TIP
This element signifies a tip or suggestion.
NOTE
This element signifies a general note.
WARNING
This element indicates a warning or caution.
This book is here to help you get your job done. In general, if example
code is offered with this book, you may use it in your programs and
documentation. You do not need to contact us for permission unless
you’re reproducing a significant portion of the code. For example, writing
a program that uses several chunks of code from this book does not
require permission. Selling or distributing a CD-ROM of examples from
O’Reilly books does require permission. Answering a question by citing
this book and quoting example code does not require permission.
Incorporating a significant amount of example code from this book into
your product’s documentation does require permission.
If you feel your use of code examples falls outside fair use or the
permission given here, feel free to contact us at [email protected].
NOTE
For almost 40 years, O’Reilly Media has provided technology and business training, knowledge,
and insight to help companies succeed.
Our unique network of experts and innovators share their knowledge and
expertise through books, articles, conferences, and our online learning
platform. O’Reilly’s online learning platform gives you on-demand access
to live training courses, in-depth learning paths, interactive coding
environments, and a vast collection of text and video from O’Reilly and
200+ other publishers. For more information, please visit
http://oreilly.com.
How to Contact Us
Exploring the Variety of Random
Documents with Different Content
confiding young ladies to quit their father's home—to abandon the
paternal dwelling——"
"Good heavens! what do you mean?" ejaculated Clarence, now
seriously alarmed. "I see that there is something at the bottom of all
this! Captain Sparks, I implore you to explain yourself. You are
evidently well-intentioned—you have shown the greatest friendship
for me—I reciprocate the feeling most cordially: fear not, then, to
speak."
"My dear Villiers," answered the highwayman, "how can I enter upon
particulars the narration of which would be most painful for you to
hear? And yet I should not be acting consistently with my duty
towards those young ladies—no, nor towards yourself who are about
to make one of them your wife——"
"Hesitate not: speak freely!" exclaimed Clarence, seeing that his
companion paused. "Should the breath of scandal have wafted to
your ear anything prejudicial to the character of my aunt, I cannot
blame your motive in confiding the fact to me. And I the more
earnestly solicit you to be frank and candid—that is, to act
consistently with your nature, which is all frankness and candour,—
and reveal to me the cause of this distrust—this want of confidence
relative to Mrs. Slingsby,—because I have no doubt of being able to
convince you that you have been misled."
"And should I succeed in convincing you to the contrary?" asked
Rainford.
"Then I should say that you had indeed performed the part of a
friend," replied Villiers emphatically. "Although I know beforehand
that such a result is impossible—yet, for your complete satisfaction,
do I declare that should you prove my aunt to be in any way an
unsuitable guardian for that dear girl Adelais, and her sister, I shall
conceive it to be my duty immediately to seek for them another
home—yes, another home—even for the few days that remain to be
passed ere I shall acquire a right to protect Adelais as her husband
and Rosamond as her brother."
"You have spoken well and wisely, Villiers," said Rainford; "but I do
not recommend any extreme measure, which might only irritate your
aunt, and perhaps lead to the forced restoration of the young ladies
to their father before you can have obtained the right you speak of. I
merely wish you to be on your guard——"
"But the grounds of your suspicion, Captain?" cried Clarence
impatiently. "Pardon my interruption—and pity my suspense."
"I do both," returned the highwayman. "And now remember that I
am no mischief-maker between relations or friends; and were it not
for the peculiar circumstances of this case, in which two innocent
young ladies are concerned, I should never have thought it worth
while to utter a word of any thing I know injurious to Mrs. Slingsby's
character—no, not even to unmask the most disgusting hypocrisy,"
added Rainford warmly.
"Do you still allude to my aunt?" demanded Clarence, colouring with
indignation.
"I do. But start not—I am not seeking a quarrel with you, Villiers—
and you promised to listen patiently."
"To no other living being should I have listened so patiently as I
have already done to you," said Clarence. "But pray let us hasten to
dispose of so disagreeable a topic in one way or the other."
"I am most anxious to do so," continued the highwayman. "Do you
know Sir Henry Courtenay?"
"Certainly: he is my aunt's best friend."
"And her lover," added Rainford coolly.
Villiers started from his seat, exclaiming, "Captain Sparks! you
presume upon the obligation which I owe you, to calumniate——"
"Then good evening, Mr. Villiers," interrupted the highwayman. "If
this is the fair and impartial hearing which you promised to give me,
—if this is the manner in which you treat one who has not—cannot
have an improper motive in offering you wise counsel——"
"Stay, my dear friend—stay!" exclaimed Clarence, actually thrusting
Rainford back into his seat; "and pray forgive my impetuosity. But
this accusation—so sudden—so unexpected—so very strange——"
"And yet it is substantially true," added Rainford emphatically: "and
it is proper that you should know it. For my part, I am not the man
to blame Mrs. Slingsby for having a lover—nor yet the lover for
having her as his mistress: it's human nature both ways. But when I
know that she has been entrusted by you with the guardianship of
two young ladies of tender age and spotless innocence, and one of
whom is so very, very dear to you, I consider it necessary for you to
be enlightened as to her true character. I've no doubt that you must
feel deeply this communication: but it is better for you to learn that
your aunt is something that she ought not to be, than to find out
when it is too late that your wife or her sister have been corrupted
by bad example."
Clarence paced the room in an agitated manner: then, at the
expiration of a few minutes, he turned suddenly, exclaiming, "Not for
a moment, Captain Sparks, do I suspect you of any sinister object:
but you will pardon me for soliciting the proof of this charge which,
if substantiated, must so completely and so painfully change my
opinion of a relative whom I have until now vaunted as the pattern
of virtue and propriety."
"The mode of proving the charge may be left to yourself," replied the
highwayman. "Did you ever hear the circumstance of your aunt's
house being robbed by a boy to whom she gave a night's lodging,
some four or five years ago?"
"Certainly," exclaimed Villiers. "I recollect the incident well. Mrs.
Slingsby herself communicated it to me. The ungrateful young villain
——"
"I know that boy," interrupted Tom Rain drily; "and I am convinced
that he told me the truth when he declared that, during the night—
or rather the portion of the night, which he passed in Mrs. Slingsby's
house, accident made him a witness to a scene which leaves no
doubt as to the fact that Sir Henry Courtenay and Mrs. Slingsby are
as intimate as man and wife together."
"And would you receive the testimony of a thief——"
"When well corroborated," added the highwayman.
"But how happened it that you should have any connexion with this
lad, Captain Sparks!" demanded Clarence, in a cold and suspicions
tone.
"Suppose that the boy has repented of his errors—that he has
merited my interest by a service which accident enabled him to
render me—that he related to me his entire history, in which this
incident is comprised—and that, on questioning him closely, I learnt
that the occurrence took place at the residence of your aunt?"
"I am bewildered—amazed—grieved—profoundly grieved!"
ejaculated Villiers. "To suppose for an instant that this kind and
affectionate relative—who has always been so good to me, and
through whose bounty I am enabled to prepare and fit up a suitable
dwelling for the reception of my beloved Adelais,—to think that this
much-respected and long-revered woman should conceal the
greatest profligacy beneath the mask of charity and religion—oh! it
is a cruel blow!"
"Again I say that the mode of proving the charge may be left to
yourself," observed Rainford. "Seek an opportunity to be alone with
Mrs. Slingsby—make some pointed allusion to the incident—and
mark how she receives it."
"I will call at my aunt's residence to-morrow morning early—the very
first thing," exclaimed Villiers. "The whole affair is most serious; and,
now that I can at length contemplate it with something bordering on
calmness, I am bound to confess——But let us quit the topic," he
added, in a tone of deep vexation, in spite of his asserted self-
possession.
"And you bear me no ill-will for the course I have pursued?" said
Rainford.
"Far from it. You have acted in a most friendly manner—whatever
the result may be!" cried Villiers, grasping the highwayman's hand
most cordially.
"I have performed a very painful duty," rejoined Tom: "and now I
must take my leave of you—perhaps for a long, long time—if not for
ever."
"Farewell," said Clarence; "and may prosperity attend you in another
clime."
"Farewell," replied Rainford; "and may you be happy with your
Adelais."
The highwayman then hurried from the room, considerably affected
by this parting from one for whom he already experienced a most
sincere regard.
Nor was Villiers unmoved by this farewell scene; for, on his side, he
was particularly attached to the individual who had not only
rendered him so essential a service on that memorable night which
first made them acquainted with each other, but whose apparent
frankness of disposition and manliness of character were well
calculated to engage the good opinion of the confiding, warm-
hearted, and unsuspecting Clarence.
CHAPTER XLV.
MR. DYKES AND HIS MYRMIDONS.
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