100% found this document useful (2 votes)
8 views

The Definitive Guide to AdonisJs: Building Node.js Applications with JavaScript Christopher Pitt pdf download

The document is a comprehensive guide to AdonisJs, focusing on building Node.js applications with JavaScript by Christopher Pitt. It covers various topics including installation, routing, views, requests, responses, and security among others, providing detailed instructions and examples. The guide is structured into chapters that progressively build on each other, making it suitable for both beginners and experienced developers.

Uploaded by

cabrapuderke
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
8 views

The Definitive Guide to AdonisJs: Building Node.js Applications with JavaScript Christopher Pitt pdf download

The document is a comprehensive guide to AdonisJs, focusing on building Node.js applications with JavaScript by Christopher Pitt. It covers various topics including installation, routing, views, requests, responses, and security among others, providing detailed instructions and examples. The guide is structured into chapters that progressively build on each other, making it suitable for both beginners and experienced developers.

Uploaded by

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

The Definitive Guide to AdonisJs: Building

Node.js Applications with JavaScript Christopher


Pitt pdf download

https://textbookfull.com/product/the-definitive-guide-to-
adonisjs-building-node-js-applications-with-javascript-
christopher-pitt/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

The Definitive Guide to JSF in Java EE 8: Building Web


Applications with JavaServer Faces Bauke Scholtz

https://textbookfull.com/product/the-definitive-guide-to-jsf-in-
java-ee-8-building-web-applications-with-javaserver-faces-bauke-
scholtz/

Ultimate Node.js for Cross-Platform App Development:


Learn to Build Robust, Scalable, and Performant Server-
Side JavaScript Applications with Node.js (English
Edition) Kumar
https://textbookfull.com/product/ultimate-node-js-for-cross-
platform-app-development-learn-to-build-robust-scalable-and-
performant-server-side-javascript-applications-with-node-js-
english-edition-kumar/

JavaScript The Definitive Guide 7th Edition David


Flanagan

https://textbookfull.com/product/javascript-the-definitive-
guide-7th-edition-david-flanagan/

Building web and mobile ArcGIS Server applications with


JavaScript Lewin

https://textbookfull.com/product/building-web-and-mobile-arcgis-
server-applications-with-javascript-lewin/
Guide to Scientific Computing in C Pitt-Francis

https://textbookfull.com/product/guide-to-scientific-computing-
in-c-pitt-francis/

Understanding ECMAScript 6 The definitive guide for


Javascript developers 1st Edition Nicholas C. Zakas

https://textbookfull.com/product/understanding-ecmascript-6-the-
definitive-guide-for-javascript-developers-1st-edition-nicholas-
c-zakas/

Practical Bot Development: Designing and Building Bots


with Node.js and Microsoft Bot Framework Szymon Rozga

https://textbookfull.com/product/practical-bot-development-
designing-and-building-bots-with-node-js-and-microsoft-bot-
framework-szymon-rozga/

Pentesting Azure Applications The Definitive Guide to


Testing and Securing Deployments 1st Edition Matt
Burrough

https://textbookfull.com/product/pentesting-azure-applications-
the-definitive-guide-to-testing-and-securing-deployments-1st-
edition-matt-burrough/

Guide to Scientific Computing in C 2nd Edition Joe


Pitt-Francis

https://textbookfull.com/product/guide-to-scientific-computing-
in-c-2nd-edition-joe-pitt-francis/
The Definitive
Guide to AdonisJs
Building Node.js Applications with JavaScript

Christopher Pitt
The Definitive Guide to
AdonisJs
Building Node.js Applications
with JavaScript

Christopher Pitt
The Definitive Guide to AdonisJs: Building Node.js Applications with JavaScript
Christopher Pitt
Cape Town, Western Cape, South Africa

ISBN-13 (pbk): 978-1-4842-3389-4 ISBN-13 (electronic): 978-1-4842-3390-0


https://doi.org/10.1007/978-1-4842-3390-0
Library of Congress Control Number: 2018937100

Copyright © 2018 by Christopher Pitt


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.
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: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
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
[email protected], 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]; for reprint, paperback, or audio rights,
please email [email protected].
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 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/9781484233894. For more
detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� ix

Acknowledgments��������������������������������������������������������������������������������������������������� xi
Introduction����������������������������������������������������������������������������������������������������������� xiii

Chapter 1: Getting Started���������������������������������������������������������������������������������������� 1


Installing Node.js��������������������������������������������������������������������������������������������������������������������������� 1
Installing the AdonisJs Command-Line Tool��������������������������������������������������������������������������������� 3
Creating a New Application����������������������������������������������������������������������������������������������������������� 3
Serving the Application����������������������������������������������������������������������������������������������������������������� 4
Exploring the Code������������������������������������������������������������������������������������������������������������������������ 5
Summary������������������������������������������������������������������������������������������������������������������������������������ 10

Chapter 2: Routing�������������������������������������������������������������������������������������������������� 11
What Are Routes?������������������������������������������������������������������������������������������������������������������������ 11
Planning Routes�������������������������������������������������������������������������������������������������������������������������� 12
Defining Routes��������������������������������������������������������������������������������������������������������������������������� 14
Testing Routes���������������������������������������������������������������������������������������������������������������������������� 15
Defining Route Parameters��������������������������������������������������������������������������������������������������������� 20
Summary������������������������������������������������������������������������������������������������������������������������������������ 26

Chapter 3: Views���������������������������������������������������������������������������������������������������� 27
Creating Views���������������������������������������������������������������������������������������������������������������������������� 27
Registering the View Provider����������������������������������������������������������������������������������������������� 28
Creating Layouts������������������������������������������������������������������������������������������������������������������������� 29
Learning Template Syntax����������������������������������������������������������������������������������������������������������� 34
Interpolation�������������������������������������������������������������������������������������������������������������������������� 35

iii
Table of Contents

Conditionals��������������������������������������������������������������������������������������������������������������������������� 36
Loops������������������������������������������������������������������������������������������������������������������������������������� 37
Partials���������������������������������������������������������������������������������������������������������������������������������� 38
Yield��������������������������������������������������������������������������������������������������������������������������������������� 38
Functions������������������������������������������������������������������������������������������������������������������������������� 39
Summary������������������������������������������������������������������������������������������������������������������������������������ 40

Chapter 4: Requests����������������������������������������������������������������������������������������������� 41
Updating Tests����������������������������������������������������������������������������������������������������������������������������� 41
Understanding Requests������������������������������������������������������������������������������������������������������������� 47
Getting Parameters���������������������������������������������������������������������������������������������������������������� 49
Getting Headers and Cookies������������������������������������������������������������������������������������������������ 50
Getting “accepts” and “language”���������������������������������������������������������������������������������������� 50
Finding Out More������������������������������������������������������������������������������������������������������������������� 51
Responding to POST, PUT, PATCH, and DELETE���������������������������������������������������������������������� 51
Summary������������������������������������������������������������������������������������������������������������������������������� 59

Chapter 5: Responses��������������������������������������������������������������������������������������������� 61
Sending Simple Responses�������������������������������������������������������������������������������������������������������� 61
Sending JSON Responses����������������������������������������������������������������������������������������������������������� 62
Working with Cookies����������������������������������������������������������������������������������������������������������������� 64
Redirecting Users������������������������������������������������������������������������������������������������������������������������ 64
Responding with Attachments���������������������������������������������������������������������������������������������������� 66
Extending with Macros��������������������������������������������������������������������������������������������������������������� 66
Summary������������������������������������������������������������������������������������������������������������������������������������ 70

Chapter 6: Generators��������������������������������������������������������������������������������������������� 71
Arrays: Where It All Began����������������������������������������������������������������������������������������������������������� 71
Then Came Iterators�������������������������������������������������������������������������������������������������������������������� 72
Generators���������������������������������������������������������������������������������������������������������������������������������� 75
Cooperative Multitasking������������������������������������������������������������������������������������������������������������ 76
Summary������������������������������������������������������������������������������������������������������������������������������������ 79

iv
Table of Contents

Chapter 7: Promises����������������������������������������������������������������������������������������������� 81
Reacting to Events���������������������������������������������������������������������������������������������������������������������� 81
Entering Callback Hell����������������������������������������������������������������������������������������������������������������� 82
Understanding Promises������������������������������������������������������������������������������������������������������������� 83
Using Promises with Coroutines������������������������������������������������������������������������������������������������� 84
Making Promises������������������������������������������������������������������������������������������������������������������������ 86
Bringing It Back to AdonisJs������������������������������������������������������������������������������������������������������� 88
Summary������������������������������������������������������������������������������������������������������������������������������������ 89

Chapter 8: Controllers and Middleware������������������������������������������������������������������ 91


Making Controllers���������������������������������������������������������������������������������������������������������������������� 91
Reusing Code������������������������������������������������������������������������������������������������������������������������������ 96
Using Middleware����������������������������������������������������������������������������������������������������������������������� 97
Summary���������������������������������������������������������������������������������������������������������������������������������� 101

Chapter 9: Databases������������������������������������������������������������������������������������������� 103


Installing Lucid�������������������������������������������������������������������������������������������������������������������������� 103
Making Migrations�������������������������������������������������������������������������������������������������������������������� 107
Seeding the Database��������������������������������������������������������������������������������������������������������������� 111
Working with Routes and the Database������������������������������������������������������������������������������������ 115
Showing Products��������������������������������������������������������������������������������������������������������������������� 116
Making Models�������������������������������������������������������������������������������������������������������������������������� 118
Registering Customers�������������������������������������������������������������������������������������������������������������� 121
Authenticating Customers��������������������������������������������������������������������������������������������������������� 125
Summary���������������������������������������������������������������������������������������������������������������������������������� 127

Chapter 10: Validation and Errors������������������������������������������������������������������������ 129


Installing Validation������������������������������������������������������������������������������������������������������������������� 129
Reusing Validation��������������������������������������������������������������������������������������������������������������������� 133
Displaying Custom Error Pages������������������������������������������������������������������������������������������������� 140
Creating Custom Exceptions����������������������������������������������������������������������������������������������������� 144
Summary���������������������������������������������������������������������������������������������������������������������������������� 146

v
Table of Contents

Chapter 11: Sessions�������������������������������������������������������������������������������������������� 147


Making the Dashboard�������������������������������������������������������������������������������������������������������������� 147
Creating the Customer Session������������������������������������������������������������������������������������������������� 154
Logging Customers Out������������������������������������������������������������������������������������������������������������� 158
Summary���������������������������������������������������������������������������������������������������������������������������������� 161

Chapter 12: Security��������������������������������������������������������������������������������������������� 163


Recap���������������������������������������������������������������������������������������������������������������������������������������� 163
Creating More Middleware�������������������������������������������������������������������������������������������������������� 164
Securing Forms������������������������������������������������������������������������������������������������������������������������� 168
Encrypting Values��������������������������������������������������������������������������������������������������������������������� 171
Summary���������������������������������������������������������������������������������������������������������������������������������� 172

Chapter 13: Front-End Tools��������������������������������������������������������������������������������� 173


Installing Mix����������������������������������������������������������������������������������������������������������������������������� 173
Installing Bootstrap (Sass)�������������������������������������������������������������������������������������������������������� 177
Installing React������������������������������������������������������������������������������������������������������������������������� 179
Summary���������������������������������������������������������������������������������������������������������������������������������� 182

Chapter 14: WebSockets��������������������������������������������������������������������������������������� 183


Installing Socket.io�������������������������������������������������������������������������������������������������������������������� 183
Building a React Shopping Cart������������������������������������������������������������������������������������������������ 189
Connecting the UI���������������������������������������������������������������������������������������������������������������������� 197
Creating Orders������������������������������������������������������������������������������������������������������������������������� 201
Summary���������������������������������������������������������������������������������������������������������������������������������� 205

Chapter 15: Deployment�������������������������������������������������������������������������������������� 207


Setting Up DigitalOcean������������������������������������������������������������������������������������������������������������ 208
Setting Up Forge����������������������������������������������������������������������������������������������������������������������� 209
Getting a Domain���������������������������������������������������������������������������������������������������������������������� 211
Adding the Domain Name in Forge������������������������������������������������������������������������������������������� 213
Setting Up DNS Servers������������������������������������������������������������������������������������������������������������ 215
Adding a Server Daemon���������������������������������������������������������������������������������������������������������� 216

vi
Table of Contents

Serving on Port 80�������������������������������������������������������������������������������������������������������������������� 220


Setting Up an SSL Certificate���������������������������������������������������������������������������������������������������� 221
Summary���������������������������������������������������������������������������������������������������������������������������������� 222

Chapter 16: Finishing Touches����������������������������������������������������������������������������� 223


Sending E-mail�������������������������������������������������������������������������������������������������������������������������� 223
Connecting to Stripe����������������������������������������������������������������������������������������������������������������� 230
Enabling CORS Requests���������������������������������������������������������������������������������������������������������� 238
Summary���������������������������������������������������������������������������������������������������������������������������������� 243

Index��������������������������������������������������������������������������������������������������������������������� 245

vii
About the Author
Christopher Pitt is a developer and writer working at Over. He usually works on
application architecture, though sometimes you’ll find him building compilers or robots.
He is also the author of several web development books and is a contributor on various
open source projects such as AdonisJs.

ix
Acknowledgments
Many people helped to make this book a reality. I’d like to thank them, in no
particular order.
Harminder and the rest of the core team have written some beautiful software.
I am continually amazed by how beautiful AdonisJs code can look. I enjoy JavaScript,
and it seems particularly suited to a framework like this. Harminder also gave insightful
technical feedback for this book.
Taylor began a wonder with Laravel. It’s clear that much of AdonisJs is inspired by
Laravel, and with good reason. Laravel kept me engaged in PHP, and AdonisJs will keep
me engaged in server-side JavaScript.
Mark, the coordinating editor, was fantastic to work with. He never got in the way
and was always helpful. That’s uncommon in his line of work. Matt, the development
editor, was similarly helpful and let me set the vision for this project, unencumbered.
These folks are a credit to Apress.
Matt, the writer, is an inspiration to me. He wrote what I consider to be the best
Laravel book on the market. Throughout this book, I sought to emulate his wisdom and
skill.
Bruno, Christian, and Wayne are good friends and supporters of my work. I miss
writing for Bruno. I miss having coffee with Christian. I will miss taking walks with
Wayne.
Liz, my love, has given me space and coffee in abundance. She is the inspiration
for the sample application, and though she finds me altogether strange, she loves me
effortlessly.

xi
Introduction
This book is designed to teach you how to use AdonisJs. To get the most out of it, you
should have a firm grasp of modern JavaScript and some knowledge of how to work with
relational databases and the command line.
I explain new and interesting bits of syntax, but this book isn’t primarily about
teaching you how to use JavaScript. It’s about teaching you how to build real applications
by using AdonisJs.
The application we’re going to build is called Threadbear. It’s a play on words,
meant to conjure up thoughts of patchy, knitted teddy bears. We’re going to make an
application through which sellers can register and upload their knitted patterns and
products. Customers will then be able to register and purchase these things.
We’re not going to focus much on design. Instead, we’re going to focus on the
mechanics of commerce applications. Beyond adding a CSS framework, everything is as
the good browser vendors intended. That said, I welcome you to add your own style to
the application
We’ll create a secure registration and login system. We’ll add profile and product
management. We’ll connect the front end to the back end by using WebSockets and
the Fetch API. We’ll design a shopping cart in React and we’ll package static files with a
custom build chain. Finally, we’ll learn how to deploy the application to a virtual server,
and install custom domains and SSL certificates.
It is my hope that by the time you are finished reading this book, you’ll know all you
need to know in order to build your online business.

xiii
CHAPTER 1

Getting Started
Deciding where to start is often the hardest part, don’t you find? In this chapter, we’re
going to get our development tools set up. We’re also going to create a new AdonisJs
application. We’ll finish up by taking a look at the folders of our application and making
a few small customizations.

Note Complex and exhaustive installation instructions are one of the easiest
ways to age a book. I’m not going to belabor the steps for every operating system
and configuration. I’m guessing you know enough about Google to find the help
you need. If you get stuck, ask me for help on Twitter (https://twitter.com/
assertchris) or e-mail ([email protected]).

I nstalling Node.js
As the name implies, AdonisJs is a JavaScript framework. There have been a few
runtimes for JavaScript on the server, but the clear winner is Node.js (https://nodejs.
org/en). You can see what the Node.js web site looks like in Figure 1-1. The latest version
of AdonisJs requires Node 8.0 or newer. That’s because it uses new language features to
make writing code easier and more expressive. We’ll learn about those later.
Node.js is relatively painless to install, despite its size and intricacy. On macOS, you
can run the following:

brew install node

And on Debian or Ubuntu, you can run this:

apt-get install node

1
© Christopher Pitt 2018
C. Pitt, The Definitive Guide to AdonisJs, https://doi.org/10.1007/978-1-4842-3390-0_1
Chapter 1 Getting Started

Note Alternatively, you can install Node.js from a binary at https://nodejs.


org/en/download. There are installers for Windows, so you don’t have to use
macOS or Debian if you don’t want to.

You can check that Node.js is correctly installed by running the following:

node -v
npm -v

Figure 1-1. The Node.js web site

2
Chapter 1 Getting Started

Installing the AdonisJs Command-Line Tool


Setting up a new AdonisJs application requires quite a few steps. Fortunately, there’s a
tool to perform all of those steps for us. We need to install that tool, which also will help
us to create all future AdonisJs applications:

npm install --global @adonisjs/cli

This installs the command-line tool globally, which means we’ll be able to use it
from anywhere on our system. Similarly to the way we check Node.js, we can check to
see whether this tool has been successfully installed by running the following:

adonis --help

This also gives as a sneak peek at the kinds of things we can start to do to an
application. Various commands are available, from creating and running applications to
adding new functionality in existing applications.
For now, we’re just going to create a new AdonisJs application.

Creating a New Application


If you read through the output of that help command, you may have noticed the new
command. It’s what we’re going to use to create a new application:

adonis new threadbear

It’ll take a minute or two to fully install and configure the new application. The
only step I want to talk about for the moment is “generated unique APP_KEY.” AdonisJs
applications have an .env configuration file, which we can use to store sensitive
configuration variables. One of these is called APP_KEY, which is a private key unique to
the application.
Whenever text is encrypted or hashed, this value is used to seed the operation. The
same password, when hashed in two applications (with different APP_KEY values), will
result in different hashes. This is important to know because at times you might need to
compare hashes or decrypt values that have been generated using a different APP_KEY
than the one the command-line tool just made for you.

3
Chapter 1 Getting Started

Note It’s possible to reuse an APP_KEY in multiple applications, but it’s definitely
not recommended. Sharing an APP_KEY should be done only in exceptional
situations and for a limited amount of time. If you reuse keys, you’re increasing the
likelihood that all the applications reusing the key are compromised at the same time.

S
 erving the Application
Now that we’ve created an application, we need a way to view it in the browser. Some
server-side languages use third-party web servers (such as Nginx or Apache) as a kind of
load balancer. PHP and Perl are examples of this.
Things work a bit differently with server-side JavaScript. The foundational example
of how to use Node.js (https://nodejs.org/en/docs/guides/getting-started-guide)
demonstrates how we can make our own HTTP server:

const http = require("http")

const hostname = "127.0.0.1"


const port = 3333

const server = http.createServer((req, res) => {


    res.statusCode = 200
    res.setHeader("Content-Type", "text/plain")
    res.end("hello world")
})

server.listen(port, hostname, () => {


    // server is now running
})

This is quite similar to what AdonisJs does under the hood. This means our server(s)
need to keep the Node.js HTTP script running as what is usually referred to as a daemon.
We’ll unpack that later, but for now we’ll need to make sure adonis serve is running
while we code.
As the message when we run adonis serve --dev says, we can see the new application
by loading 127.0.0.1:3333 in a web browser. We can see what this looks like in Figure 1-2.

4
Chapter 1 Getting Started

Figure 1-2. A new AdonisJs application

E xploring the Code


New AdonisJs applications are as slim as the repository’s name on which they are based.1
They look something like this:

threadbear
↳ node_modules
↳ public
↳ start
↳ .env
↳ .env.example
↳ .gitignore

1
https://github.com/adonisjs/adonis-slim-app

5
Chapter 1 Getting Started

↳ ace
↳ package.json
↳ server.js

As usual, NPM (or Node Package Manager) dependencies are stored in the node_
modules folder. When we run adonis serve --dev, it’s doing little more than running
node server.js.
Static files, such as client-side stylesheets and scripts, are usually placed in the
public folder. More complex applications tend to have build chains, which take source
stylesheets and scripts and combine/compress them into smaller production versions.
AdonisJs favors convention over configuration. This means that it is designed to be
useful out of the box. Sometimes we might need to deviate from the standard configuration.
In new applications, we can do that by customizing the files in the start folder.
Let’s make a few customizations to the application. We’re going to learn about routes
in a while, but we’ll add one in the meantime. The starting routes file resembles Listing 1-1.

Listing 1-1. This is from threadbear/start/routes.js

"use strict"

const Route = use("Route")

Route.get("/", ({ request }) => {


    return "...some html"
})

See that Route.get? We’re going to add another, as shown in Listing 1-2.

Listing 1-2. This is from threadbear/start/routes.js

Route.get("/register", () => {
    return "...form for customers to make new profiles"
})

For now, restart the serve command and go to the address you see in the terminal
window. We can see the text we entered: text that we’re returning from the route, matching
the /register path we specified.
Larger applications require more files than just the ones we have currently. You may
remember that the adonis --help command suggested quite a few make commands.

6
Chapter 1 Getting Started

We can use these to create any number of project files. Though we’re also going to learn
about them later, let’s create a controller:

adonis make:controller PageController

This creates a nested folder structure: app ➤ Controllers ➤ Http ➤


PageController.js.
Similarly, the other make commands usually put the files they create in the app folder,
and create more nested folders if they don’t already exist. There’s quite a rich structure
built up as needed. The pattern is always the same, leading back to the convention-over-­
configuration paradigm.

Note The command-line tools create files in a predictable location. That’s not
to say that we couldn’t change the position and name of these files—just that by
default, they will always be in a predictable configuration.

Let’s make a new command so we can explore more of the starter configuration:

adonis make:command SendReminderCommand

This command creates a new command-line command class, located in app ➤


Commands ➤ SendReminder.js. It automatically strips the Command suffix and gives some
help for how to add the command to Ace.
Ace is a local version of the adonis global command-line helper. We can run it with
the following:

node ace

The output is similar to (though much less than) that of adonis --help. These
commands are similarly built, but the global adonis command has more subcommands
registered within it. ace has only the commands registered for your app.
Sometimes it’s easier not to have to specify that you want to run the command by
using node. In that case, we can make the Ace script executable:

chmod +x ace

7
Chapter 1 Getting Started

We also need to add a hash-bang (#!) to the top of the Ace script, as in Listing 1-3.

Listing 1-3. This is from threadbear/ace

#!/usr/bin/env node

"use strict"

// ...other code

Now we can run Ace by using the following:

./ace

It’s not a huge improvement, but it is an interesting technique to be aware of. Hash-­
bang directives (like this one) can be useful for hiding unnecessary details, such as the
binary we need to run a script, so that these kinds of stand-alone scripts are easier for
others to use.
We’re going to use this trick later, when we work out how to restart the server with
a new routing configuration. In the meantime, let’s follow the advice we received when
we created the command. Let’s change start/app.js to include the new command, as
shown in Listing 1-4.

Listing 1-4. This is from threadbear/start/app.js

// ...other code

const commands = [
    "App/Commands/SendReminder"
]

module.exports = {
    providers, aceProviders, aliases, commands
}

The command code Ace generated resembles Listing 1-5.

Listing 1-5. This is from threadbear/app/Commands/SendReminder.js


"use strict"

const { Command } = require("@adonisjs/ace")

8
Chapter 1 Getting Started

class SendReminder extends Command {


    static get signature() {
        return "send:reminder"
    }

    static get description() {


        return "..."
    }

    async handle(args, options) {


        this.info("...")
    }
}

module.exports = SendReminder

SendReminder extends the built-in Command class. Command does most of the heavy
lifting, but it does require a few properties/getters to be defined:
signature is the name by which the command will be called, but also the arguments
and extra parameters the command accepts.
description is useful when we run ./ace --help. It shows what the command does
and describes what the arguments and parameters are for.
handle is where we put all the code this command needs to use. We’re going to use it
to send reminder e-mails to our customers, but for now it can log text to the console.
We can see the results of this code in Figure 1-3.

Figure 1-3. The output of ./ace send:reminder

9
Chapter 1 Getting Started

Summary
In this chapter, we installed all the requirements for AdonisJs. We created a new
application, and learned how routes and shared code (such as Ace commands) can be
configured in the files within the start folder.
We’ve touched lightly on a few parts of the AdonisJs application structure. In the next
chapter, we’re going to learn far more about defining application routes.

10
CHAPTER 2

Routing
In the previous chapter, we set up our environment and got our first look at the structure
of an AdonisJs application. Now it’s time to add HTTP endpoints to the application. This
is done by adding routes. We’ll learn about all the ways to customize routes, use the data
they hold, and respond to any request.

What Are Routes?


Routes are like glue between the HTTP requests your browser makes and the server code
meant for each request. This isn’t the first time we’re seeing them, either. In the previous
chapter, we created a /registration route (though we didn’t do any meaningful work
through it).
Routes are an essential part of every application, because every application has at
least one of them. In fact, applications can have many routes, and you’re not limited in
the length, complexity, or number of them your application can have.
The Web is built on top of a communications protocol called HTTP. It has quite a lengthy
definition, but the important bits describe how browsers (and other clients) can make text-
based requests to servers. Those requests include details such as the type of request being
made (the request method) and the server address to which the requests should be sent.
Let’s take another look at the route we defined in the previous chapter, in Listing 2-1.

Listing 2-1. This is from threadbear/start/routes.js

Route.get("/register", () => {
  return "...form to make new profiles"
})

11
© Christopher Pitt 2018
C. Pitt, The Definitive Guide to AdonisJs, https://doi.org/10.1007/978-1-4842-3390-0_2
Chapter 2 Routing

We can tell a couple of things about this route, even if we remove all the code inside
() => {...}. The first is that this route responds to GET requests. There are other kinds
of requests, such as POST, PUT, DELETE, and HEAD. The second thing we can tell is that the
request should go to /register.
Routes can also have values embedded in the path, as we’ll see in this chapter.

Planning Routes
We’re going to define a few more customer routes alongside the /registration route we
already defined. Customers will need these to manage their accounts and gain access to
protected profile and product information:

• GET /login: GET is the most common request method on the


Internet. It’s the go-to method for fetching information in a read-only
way. Similarly to the way we used GET to show the registration form,
we’re using it here to show the login form.

• POST /login: POST is more common than GET when it comes to


creating things. In this case, we’d be creating new customer sessions
(and getting back security tokens). It’s not crucial to understand how
we do that right now. All you need to know is that we want to use
POST because we’re making something.

• PUT /logout: PUT is similar to POST in that it’s used for a write
operation. However, whereas POST is often used to indicate that a
whole new thing is being created, PUT is often used to indicate that a
change is being made to something. As you’ll see, we use PUT when
we want to update something that has already been created.

• POST /register: We already have a route for showing the


registration, but this one is for creating a new customer profile.
Notice that we use the POST method, as we’re creating a whole new
customer account.

• GET /forgot-password: When customers forget or lose their


passwords, we need a way for them to request to set a new one. The
only practical way for us to allow this is to send an e-mail to their
address on record, which contains a link (and security token) they can
click. This endpoint should show users a form with which to do that.
12
Chapter 2 Routing

• POST /forgot-password: After the customer has entered their e-mail


address, the form should be posted to this endpoint. The server code
running here will then send them the e-mail. You should start to see
a pattern here: we use GET to show forms, and POST to create new
things from those forms.

• GET /reset-password/{token}: Similarly to the way the customer


requests to set a new password, this endpoint shows the form they
can use to enter a new password. It has an added {token} parameter,
which we’ll learn about shortly.

• PUT /reset-password/{token}: After the customer has entered a


new password, the form can be posted to this endpoint. Because the
customer’s profile already exists (and we want to make an update to
it), we use the PUT request method.

• GET /{user-name}: After the customer has a profile, we want them


to be able to see what information is visible on it. This is where the
customer will see their protected information, and where other
customers will be able to see details marked as open to the public.

• PUT /{user-name}: Should the customer wish to change details


about their account, they would be able to do so through forms that
send their data to this endpoint. Because it’s a partial update, we use
the PUT method.

• DELETE /{user-name}: Customers should also be able to delete


their profiles, which is a good opportunity for us to use the DELETE
method. It acts a lot like the GET method, except that it is not read-­
only. Deletes are serious business, so we should confirm whether the
customer initiated the process by accident or on purpose.

• GET /{user-name}/products: In our design, customers are also


sellers. They’ll be able to create new products (which is an entirely
optional part of their experience), and those products will be
accessible through this endpoint.

• POST /{user-name}/products: Should the customer want to create


a new product, they’ll be able to do so via this endpoint. Because
they’re creating a whole new product, we use the POST method.

13
Chapter 2 Routing

• GET /{user-name}/{product-name}: If a customer wants to find out


more details about a specific product, they will be able to do so by
using this product-specific, customer-specific endpoint.

• PUT /{user-name}/{product-name}: Similarly, if a customer wants


to update the details of a product, they should be able to do so via a
PUT request to the same endpoint. It’s a partial update, or else we’d
use the POST method.

• DELETE /{user-name}/{product-name}: Finally, if a customer wants


to delete a product, they should use the DELETE request method on
this endpoint.

Note There’s a fine line between respecting a seller’s desire for privacy and
other customers’ right to access content they’ve purchased. It is right for us to
immediately delete products and customer profiles at the will of the customer. It’s
also important for us to preserve the ability to download purchased content after
a profile has been deleted or a product removed from sale. We’ll cross this bridge
when we get to it, but it’s important to remember these rights and responsibilities
when we design the application.

D
 efining Routes
Now that we’ve planned the routes we’ll begin our application with, it’s time to define
them in code. We’ll begin with the profile routes, shown in Listing 2-2.

Listing 2-2. This is from threadbear/start/routes.js

Route.get("/login", () => {
  // show login form
  return "GET /login"
})

Route.post("/login", () => {
  // create new customer session

14
Chapter 2 Routing

  return "POST /login"


})

Route.put("/logout", () => {
  // expire current customer session
  return "PUT /logout"
})

Route.get("/register", () => {
  // show registration form
  return "GET /register"
})

Route.post("/register", () => {
  // create new customer profile
  return "POST /register"
})

Route.get("/forgot-password", () => {
  // show forgot password form
  return "GET /forgot-password"
})

Route.post("/forgot-password", () => {
  // create new password reset token and send e-mail
  return "POST /forgot-password"
})

Each of these routes follows the pattern I just described. They will grow to contain
the functionality of the application, but in the meantime they just return strings. This is
immediately useful for testing, covered next.

Testing Routes
We’re going to take a brief detour from our route definitions to testing. This book has no
chapter dedicated to testing, because I believe it’s better to always be asking ourselves
how we plan to test the code we’re writing.

15
Chapter 2 Routing

There are many schools of thought when it comes to testing. I’m not going to dwell
on any of them (because we don’t have the time, and we need to stay focused), but I will
say that no one approach to testing is the best. Having any tests is better than having
none, and thinking about tests early and continuously has caused me to write better
code. I recommend this approach.
The jury is still out on which testing framework is the best. For now, we’re going to
use a framework called Mocha (https://mochajs.org). To install it, we need to run the
following command:

npm install --save-dev mocha

This gives us access to a few tools we can use for testing. Now let’s create a test file to
hold our first test, as shown in Listing 2-3.

Listing 2-3. This is from threadbear/test/routes.js

const assert = require("assert")


const http = require("http")

require("dotenv").config()

const shouldBeOk = (method, path, done) => {


  http
    .request(
      {
        host: process.env.HOST,
        port: process.env.PORT,
        method,
        path,
      },
      response => {
        assert.equal(200, response.statusCode)
        done()
      },
    )
    .end()
}

16
Chapter 2 Routing

const shouldHaveMessage = (
  method,
  path,
  message,
  done,
) => {
  http
    .request(
      {
        host: process.env.HOST,
        port: process.env.PORT,
        method,
        path,
      },
      response => {
        let data = ""

        response.on("data", chunk => {


          data += chunk
        })

        response.on("end", () => {
          assert.equal(message, data)
          done()
        })
      },
    )
    .end()
}

describe("GET /login", () => {


  it("should have the correct status (200)", done => {
    shouldBeOk("GET", "/login", done)
  })

  it("should have the correct message", done => {


    shouldHaveMessage(
      "GET",
17
Chapter 2 Routing

      "/login",
      "GET /login",
      done,
    )
  })
})

We begin by importing the assertions and HTTP libraries via require statements. We
also import the dotenv library and immediately call the config method. This loads all
the environment variables in our .env file so we can build a URL from the HOST and PORT
variables.
We follow this up by creating the shouldBeOk and shouldHaveMessage helper
functions. The first checks whether a request to an address returns a response with a 200
status code. This would indicate that the request returned successfully, which tells us
that the route is defined.
The shouldHaveMessage function tells us whether a request to an address returns a
message we expect. We’ve defined our routes to return simple messages that describe
their method and path, so we can use shouldHaveMessage to make sure the requests
match the messages we expect them to.
We’ve also defined our first set of tests using the describe and it functions. Mocha
provides these for us, so we don’t have to import them. We can duplicate these tests for
each route, as demonstrated in Listing 2-4.

Listing 2-4. This is from threadbear/test/routes.js

describe("POST /login", () => {


  it("should have the correct status (200)", done => {
    shouldBeOk("POST", "/login", done)
  })

  it("should have the correct message", done => {


    shouldHaveMessage(
      "POST",
      "/login",
      "POST /login",
      done,
    )

18
Other documents randomly have
different content
dropped upon Cotton, to be kept in a close Ivory Box. Yet I could not
so much approve of these Things, as they were used; because they
so much dilated the Pores of the olfactory Organs, as to give more
Liberty for the pestilential Miasmata to pass in along with them.

T H E Purification of Houses was contrived to be done several


Ways; but what I most approved of, was in placing a Chafing-dish in
the Middle of a Room, or the Entries, or Windows, where proper
Things were burnt, and exhaled all round. Quicklime was likewise
thrown into the following Decoction.
℞ Fol. Scordii, Angelicæ ana M iij. summit. lauri, rutæ,
lavendulæ ana M j. [ss.] flor. rosar. pallid. sambuci ana p. ij. calami
aromat. ʒ v. Caryophyll. Contus. ʒ iij. F. decoctio in duabus p. aq.
font. & tertiâ aceti rosac. vel Sambuc. consimiliter ac lagenæ, à
mucore, & setu calcis extinctione mundantur, ita ut liquorem inditum
amplius vitient, & corrumpant. For as soon as the Lime is thrown in,
it raises a very penetrating Steam, which seemed very likely to
destroy the Efficacy of the pestilential Miasmata. For the same
Purpose likewise were the following very judiciously contrived.
℞ Salis petræ lib. j. Sulphuris ℥ iij. benzoin. Styracis simul liquati.
ana q. s. ut formentur s. a. Trochisc. deb. exiccandi.

FINIS.
OF THE
Different Causes
OF
Pestilential Diseases,
And how they become
Contagious.

WITH
REMARKS
Upon the Infection now in
FRANCE,

And the most probable Means to


prevent its Spreading here.

By John Quincy, M. D.
LONDON:

Printed for E. Bell, at the Cross Keys in Cornhill; and J.


Osborn, at the Oxford-Arms in Lombard-street, 1720.
OF THE

Different Causes

OF

Pestilential Diseases, &c.

T H E R E is hardly any one Subject more largely treated of by


Physical Writers, than that of Pestilential Diseases; and the
Reason of it I take to be, the Frequency in all Ages and Countries, of
Alarms from such dreadful Destroyers; and the uncommon
Impressions they are apt to make upon the Minds of those, whose
Profession naturally leads them to enquire into their Causes. But in
this it has fared as with all the other Branches of that noble Science.
The Conjectures and Opinions of Persons have at all Times been too
much influenced by the Philosophy in Vogue, insomuch that it is
almost an endless as well as an unprofitable Task, to examine into
them all: And as such an Enquiry is not consistent with the intended
Brevity of these Pages, I shall pass them by, only just taking Notice
of the most considerable Opinions, under which, most that has been
advanced to any Purpose may be reduced.
A L L Authors upon this Subject, may be reduced under these
two Sorts: Such as ascribe them to the immediate Wrath of Heaven,
and account them as Punishments inflicted by the immediate
Exertion of a Supernatural Power; and such as assign for their Origin
some natural Cause.
A L T H O U G H too great a Regard cannot be had to the Author
of our Beings, yet Care should likewise be taken, not to ascribe
every Calamity to the immediate Exertion of the Almighty Power; for
it seems much more worthy of the Divine Being so to order it, that
from the Course of second or natural Causes, Punishments shall
pursue Offenders, than to imagine the frequent Exertion of his
Power in a Way supernatural to inflict such Punishments. But there is
a great deal of Reason to suspect, that the Number of this Sect was
very much increased by such, as either out of Ignorance in other
Causes, or out of an affected Devotion, thought it their Interest to
come into this Opinion, and pretend to do greater Cures by certain
religious Performances, and their Intercession with Heaven, than
was in the Power of Medicine, of which they knew but very little.
O F those that assign some natural Cause, there are several
Opinions: Some ascribe them to astral Influences, to malign
Conjunctions and Radiations of the Heavenly Bodies. We find, from
the most remote Antiquity, not only Pestilential Diseases, but
likewise a great many others, ascribed to the same Causes: But all
the Reasonings about this Conjecture have been very obscure and
perplexed until the present Age, when Sir Isaac Newton first taught
Men to think justly, and talk intelligibly about the Motions and
Influences of those remote Bodies upon our Atmosphere: And upon
his Theory Dr. Mead has since further proceeded to determine their
Efficacies upon humane Bodies. By which, as it does appear that
they affect us no otherwise than as they occasion the several
Variations of the Seasons, and different Constitutions of the Air, the
Reader must be left to the Consideration of such Causes.
A N O T H E R Cause is charged upon Steams and Exhalations
from putrefying Bodies. There are Abundance of Instances to
support this Opinion, that manifestly discover very fatal Effects from
such Causes. As Battels are generally fought in Summer-Time, when
by the Heat of the Season Things are most disposed to Putrefaction,
so it has often been observed, that the Plague has appeared after
great Slaughters of Men in Fight, as appears by undoubted
Testimony from Julius Alexandrinus[1], Diodorus Siculus, and a great
many others, too tedious to mention. Ambrose Parrey[2] gives a
Relation of a Plague, that laid waste almost a whole Country, which
had its Rise from the Stench of a great many human Carcases that
were thrown into one Pit, and left Rotting uncover’d. Joannes
Wolfius[3], Forestus[4], the above-mentioned Parrey[5], and
Agricola[6], all take Notice of Plagues arising from the Stench of
putrifying Fish that were thrown dead upon the Shores.

O T H E R Steams of the same Efficacy frequently arise from the


Putrefactions of stagnant Waters, and other Bodies, which, in some
particular Constitutions of Air, are apt to corrupt and emit very
offensive Effluvia. Dr. Mead[7] relates from Diogenes Laertius[8], that
Empedocles observed a pestilential Disease to afflict the Salinuntij,
from the Putrefaction of a certain River; to remedy which, he
contrived to have the Streams of two other neighbouring Rivers
drained into it, which, by their Increase of the Current, with an
additional Weight and Pressure of Water, brought the former to its
usual Sweetness, and so put a Stop to the Plague.

T O this Purpose Dr. Plot[9] observes, the Reasons why Oxford


is now much more healthful than heretofore, to be the Enlargement
of the City, whereby the Inhabitants, who are not proportionably
increased, and not so close crowded together; and the Care of the
Magistrates in keeping the Streets clear from Filth: For formerly (he
says) they used to kill all Manner of Cattle within the Walls, and
suffer their Dung and Offals to lie in the Streets. Moreover, about
those Times the Isis and Cherwell, thro’ the Carelessness of the
Townsmen, being filled with Mud, and the Common-Shores by such
Means stopped, did cause the Ascent of Malignant Vapours
whenever there happened to be a Flood. But since that, by the Care
and at the Charge of Richard Fox, Bishop of Winchester, in the Year
1517, those Rivers were cleansed, and more Trenches cut for the
Water’s free Passage, the Town has continued in a very healthful
Condition; and in a particular Manner so free from Pestilential
Diseases, that the Sickness in 1665, which raged in most Parts of the
Kingdom, never visited any Person there, although the Terms were
there kept, and the Court and both Houses of Parliament did there
reside.
T O this Cause, ’tis very probable, is owing the Frequency of the
Plague at Grand Cairo in Egypt, and in the Island of Sardinia, as
Pæusanias and others relate: Although indeed Prosper Alpinus[10]
charges a great deal of the Cause of that at Cairo, upon their
continual Commerce with such Nations as are seldom without such
infectious Diseases. And for this Reason it is, that we find all those
Countries, which most abound with Swamps and Standing-Waters,
to be most unhealthful, especially in the hottest Seasons; except, as
in several Parts of Italy, such Lakes have any Communication with
the Sea, or some large Rivers. To this purpose Piso[11] frequently
observes those Places to be most subject to such Calamities, where
there are constant Heat and settled Calms, as such a Temperament
of Air most disposes Bodies to Putrefaction and Corruption, as in St.
Thomas Island, and Guinea: And, on the contrary, that
notwithstanding the Intenseness of Heat, if the Fluids are but
agitated by Winds, Tides, and Currents, there is little Danger of such
Diseases; and the less still, the more regular and constant the
Seasons are upon other Accounts: By which Means it is, that
between the Tropicks, and even under the Equator, it is very
healthful.
U N D E R this Head it may not be improper to observe, that too
scanty and mean a Diet, and Feeding upon unripened and unsound
Fruits, are frequently charged with a Share in Mischiefs of this kind.
Josephus[12] and Julius Cæsar[13], amongst Historians; Forestus,[14]
and several other physical Writers, give Accounts of Plagues from
the like Causes. Galen[15] is very positive in this Matter; and in one
Place[16] accuses his great Master Hippocrates with Neglecting too
much the Consequence of a bad Diet, and ascribing some Mischiefs
arising from thence to a bad Air. And upon this is grounded the
common Opinion of a Plague’s following a Famine; in which
Circumstances, the poorer sort, who feed meanest, generally suffer
most, as it frequently happens in long Sieges, and Armies ill supplied
with Provisions. Thus Travellers report, that Surrat in the East-Indies
is seldom or never free from a Plague, which is ascribed to the mean
Diet of the Natives, who are Banians, and feed on little else than
Herbs, Water, Rice, and such like pitiful Fare; for it is observed, that
the Europeans who trade there, are in no Danger of being infected,
because they feed well on Flesh, and drink Wine, which secures
them against those malignant Diseases.
A Third Cause is ascribed to Mineral Eruptions and
subterraneous Exhalations. Pestilences from this Cause are more
infrequent than from several others; because such Eruptions hardly
ever happen but upon Earthquakes, or Breaking into the Bowels of
the Earth by Mines, Pits, Wells, and the like; and then too, in Order
to produce a Pestilence, it is necessary that whatsoever exhales and
mixes with the ambient Air, must be of such a Nature, as to render it
unrespirable; or to communicate by it such Particles to the Animal
Juices as will pervert their natural Crasis, and disturb their due
Secretions; which does not often happen, for there are frequent
Shocks of the Earth from intestine Fermentations, which are not
followed by any such Mischiefs, as they happen only from the
Struggle of such Principles, as when they have got Vent, neither of
themselves, or by any Thing emitted with them, are of that
disagreeable Nature, as to give any Disturbance to the Animal
OEconomy.

C A R O L U S de la Font,[17] indeed, as well as several others,


lays great Stress upon Causes of this kind, and charges Pestilential
Diseases chiefly to Mineral Exhalations of divers kinds; as Arsenical,
Mercurial, Sulphurous, &c. which he imagines the ambient Air often
to be overcharged with, either from the Heat of the Sun,
Earthquakes, or subterraneous Fires. To all this, Persons of different
Opinion object, the Infrequency of Plagues in Calabria, Naples, and
several Parts of Sicily, where there are manifestly very great
subterraneous Fires, such as occasion violent Earthquakes, and
many furious and plentiful Eruptions of metallick and mineral Fumes.
A very distinct Relation of which, from his own Knowledge, may be
met with from Dr. Bernard Connor,[18] who has been very curious in
his Enquiries hereinto.
B U T however Authors differ upon this Head, several very odd
Relations are to be met with in History of malignant and deadly
Sicknesses from these Causes. That Story is very strange which is
related by Ammianus Marcellinus,[19] and taken Notice of by Cardan
and Riolanus, that a most grievous Pestilence broke out in Seleucia,
which, from thence to Parthia, Greece, and Italy, spread it self thro’
a great part of the World, from the Opening an ancient Vault in the
Temple of Apollo, and that it raged with so much Fury, as to sweep
away a third part of the Inhabitants of those Countries it visited.

I T is needless to trouble the Reader with many Relations of the


sudden and strange Effects of some Steams arising from Mines and
Pits, which are generally termed by our Colliers Damps, because
almost every Body has already been acquainted with such Accounts.

D R . Plot[20] tells us, That about Twenty Years since, two


Persons were employed to dig a Well in the Parish of North-Leigh in
Oxfordshire, but upon being taken ill, left off the Work: Whereupon
it was undertaken by two others of Woodstock; who, before they
could do any thing considerable in it, sunk down, and died
irrecoverably in the Well: Which being perceived by a Miller hard by,
and he coming to their Assistance, fell down dead upon them.
Another also venturing to do the same, with a Rope tied about him,
fell from the Ladder just in the same Manner; and though presently
drawn up by the People above, yet he was scarcely recover’d in an
Hour or more. And since then, upon a Bucket’s falling into a Well in
another Part of the Town, a Woman perswaded a strong lusty Man
to go down a Ladder to fetch it, who, by that Time he had got half
way down, fell from the Ladder into the Well; upon which, the
Woman called another of her Neighbours to his Assistance, who,
much about the same Place, met with the same Fate, without giving
the least Sign of Change; so fatal (says the Doctor) are the Damps
of that Place. Dr. Boot[21] tells a Story that happened at Dublin in
Ireland, just of the same Nature. And in the Philosophical
Transactions[22], there are the like Relations of Damps in the Coal-
Mines belonging to the Lord Sinclair in Scotland.
T H E most surprizing Effect of these subterraneous Effluvia that
I ever met with, is in a Relation of Dr. Bernard Connor, of certain
Persons in Paris digging deep in a Vault or Cellar, who were so
suddenly transfixed by some subtile Vapour, that when a Servant-
Maid came down to speak with them, she found them in Postures as
if at Work; one with his Pick-Ax advanced, another with his Shovel
full of Earth, half lifted up, and a Woman sitting by with her Arm
upon her Knee, her Head leaning upon that Hand, with manifest
Expectations in her Countenance of what they were in Search after.
T H E same Author, from his own Knowledge, gives a very exact
Account of a Grotta in Italy, much talked of, and commonly called la
Grotta de cani, by this Author, Crypta Κυνιχυς; But Dr. Mead hath
since, from his own Knowledge also, given a very particular and
rational Account of this Place, and the Manner of its killing; to whom
therefore the Reader may turn for further Satisfaction.
A N O T H E R , and more general Cause than any hitherto
mentioned of these Maladies, is some bad and unwholsome
Constitution of Air. Such Constitutions may arise from several
Causes, which although they affect us in different Manners, yet as
they are equally fatal, we call them all Malignant or Pestilential: In
Order therefore to understand the better how we are differently
affected by those different Constitutions, it will be proper to consider
them somewhat distinctly, under these general Heads, viz. A dry hot
Air, hot and moist, cold and moist, and cold and dry; to which most
Variations of Air may be reduced.

T H A T from the several Constitutions of Air, our Bodies are


differently affected; and that most Diseases are in some Measure
more or less influenced thereby, is quite out of Dispute. Hippocrates,
in a great many Places declares himself of this Mind: His whole third
section of Aphorisms is a Proof of it; and in several Places[23] he
discovers his Opinion, that Pestilential Diseases have their Rise from
hence. Galen, his best Interpreter, understood his το θειον, which
some will have to be meant of somewhat Divine, or the immediate
Hand of God, to be nothing else but a particular Constitution of Air
arising from natural Causes; and that he was of the same Mind
himself, is very plain from his own Writings[24].
I T is almost endless, as well as altogether needless, to cite all
the Authorities for this Opinion, that might be collected from the
most remote Antiquity down to the present Age. We shall therefore
proceed to consider the different Constitutions of Air, according to
the forementioned Distinction; premising only, that the Terms Hot,
Cold, &c. are used in a twofold Sense, the one is Absolute, and the
other Relative; by the former, viz. Absolute Heat, Cold, &c. is
understood one simple Property of the Air only, as it is different not
in Degree, but in Quality from others: By the latter, that is, Relative
Heat, &c. is meant certain Degrees of those Properties: As the same
Air may at the same Time be said properly to be both Hot and Cold,
or Dry and Moist, as it is compared with another Air, either Hotter or
Colder, Dryer, or Moister; for with Regard to a hotter Air, it will be
termed cold, when at the same Time if it be compared to a colder
Air, it would be accounted hot: And so of the rest. To which
Distinction, it is very necessary to have constant Regard to avoid
Confusion.

T H O S E Countries where the Air is hot and dry for the greatest
Part, are related to be healthful, and free from Pestilential Diseases,
except where there are great Swamps and stagnant Waters, or by
any accidental Causes Bodies are exposed there to Putrefaction, the
Steams of which render Persons Diseased. In such Countries, for the
most Part of the Year, there is but very little Rain, and the Nights are
comparatively colder than elsewhere, from the great Dews which
then fall. As Piso[25] informs us, that the colder the Nights are in
Brasil, and the more plentifully the Dews fall, the Inhabitants
account it most agreeable to their Soil, and conducive to Vegetation;
and Physicians reckon it much the most healthful for the Inhabitants.
T H E Heat of the Air alone, where it is constant and uniform,
does not appear to render Persons born in it, or long accustomed to
it, any more unhealthful, than that which is more temperate.
Aristotle[26] indeed says, a hot and dry Southerly Wind will bring a
Pestilence; but of such we have very few Instances, especially on
this Part of the Globe. There is in Livy[27] an Account of a Plague at
Rome, from a great Drought; and Nicephorus[28] relates such
another: But these generally come from some other manifest Causes
besides Heat, and in Places not accustomed to a dry Air.
B U T a hot and moist Air is very different. By Moist, is meant
what arises from sudden or long Rains. This is the Constitution of Air
that most Authors charge with being the greatest Instrument in
Pestilential Distempers. Hippocrates[29] ascribes a great deal to such
an Air, and relates a Pestilence that had its Rise from great Heat,
joined with Southerly Winds and much Rain. Galen is of the same
Mind, as appears from several of his Writings[30], with many others
too tedious to mention. The Truth of this is likewise manifest from
the Histories of those Countries, where there are long settled Heats,
and afterwards much Rain, as in several Parts of the East-Indies,
which are known at such Times to be most grievously afflicted with
Fevers and Diseases of a very malignant Kind. The same we are
informed of from some Places in Africa,[31], viz. That if Showers fall
soon upon the sultry Heats of July and August, pestilential
Distempers certainly ensue. It may be generally observed here too in
our own Climate, that the most unhealthful Times are after warm
Rains, and the more if the Air is then agitated but little with Winds.
F R O M a cold and moist Air, we have little complained of, as to
their occasioning these Diseases, unless such a Constitution sets in
immediately upon a contrary Extream; for all sudden Changes of
Weather are more or less unhealthful, as well as in other Respects of
living; for which Reason particularly, Corn. Celsus advises to be very
slow in all Alterations of Moment: And Sanctorius frequently
inculcates the same in his Aphorisms, and tells us[32] how it is
hurtful, both to go suddenly out of a hot Air into a cold one, and out
of a cold Air into a hot one; and is also very particular[33] in the
Inconveniencies of such a Constitution of Air we are now speaking
of, setting in after the Heat of Summer. Hippocrates[34] does tell us
of a Pestilence from long continued cold Rains, as likewise does
Fernelius[35], but such Instances are not common.
T H E last Constitution of Air we are to take Notice of, is that
which is cold and dry, against which there are a great many very
heavy Complaints. Galen writes of a most Raging Pestilence about
Aquileia in Italy, that began in the very Middle of Winter, and had its
manifest Cause in extream Cold. Fernelius[36] asserts the Rise of
several Pestilences from the same Causes: As also does Morellus[37]
observe great Malignities to proceed from some Northerly cold
Winds. Titus Livy[38] likewise mentions a Pestilential Constitution
arising from intense Cold, but Physical Histories abound with such
Relations.

O F the strange and sudden Effects of intense Cold and dry


Winds, we have very surprizing Accounts from those who have
travelled into Countries where they are the most frequent. Dr.
Bernard Connor[39] beforementioned, relates, That when he was in
Poland, it was asserted to him by very creditable Testimonies, that it
frequently happens in Lithuania, and some of the Northern Tracts of
Muscovy and Tartary; that if sometimes, through the Neglect of the
Shepherds, their small Cattle, as Sheep, Goats, and the like, be left
exposed in the Night-time to the Northerly Winds, they are
frequently found next Morning perfectly stiff and dead, in the same
Posture as they are wont to be in at their Stalls and Cribs: And there
are divers Accounts of Persons in those Countries, who have been so
suddenly transfixed, stiffened, and killed by those Blasts, as to have
continued on Horseback in the same Posture as when Living, till the
Horse, acquainted with the Road, has brought them to their
Journey’s End: And the above-mentioned Physician[40] tells us, that
when he was at Brussels, he was informed by a Spanish Captain,
that of a Party of Horse that was sent out for Booty in a very cold
Season, one by Accident lost the rest of the Body; and Riding about
some time, before he could find his Way, or any Refreshment, he
was so transfixed with the Cold as to be quite killed, but continued
on Horseback in the Posture of a Live Person, until his Horse at last
happened to find the Way back to his Quarters, whither his
Company had before got, and missing him, feared he had fallen into
the Enemies Hands; but when they came to congratulate him upon
his safe Return, they went so near as to speak to him, and take hold
of him, before they perceived him to be dead.
T O Blasts of this kind it undoubtedly is, that Fruit Trees and
Plants do so frequently suffer, especially after a warm early Spring,
after the vegetable Juices have began to rise and shoot into Buds
and Leaves. Instances of this Nature we frequently find in our own
Countrey; and I have had Opportunity to observe, more than once,
that upon such Blasts, the Trees have, on that side towards the
Wind, been in one Night’s Time quite changed in the Colour of the
Leaves; and some, of the most tender sort, almost stripped bare,
their Leaves falling off dry, as in Autumn.

B U T there is something yet further, besides particular


Constitutions of Air, that is taken Notice of by Physicians, as a
general Cause of Maladies of this kind; and that is what is commonly
called Contagion or Infection; by this Term Contagion, is understood
a Disease arising from the Contact of such Bodies or Particles as
have in them a Power of Altering the due Crasis of a healthful
Person, and inducing still one common Disease; these Particles are
generally called by Physical Writers μιασματα, Contagiosa, or
Contagij Seminia; and the Difference of Pestilences arising from
these Causes seems much to differ from what have been hitherto
taken Notice of, as the former cannot be shunned but by quite
leaving the diseased Climate, or by such a Strength, or Turn of
Constitution, as resists, or yeilds not to the general Disorder;
whereas in this last Case, a Person seems to be equally safe in any
Air that is not impregnated with these contagious Effluvia, and the
greatest Danger arises from the Nearness to diseased Persons, or
whatsoever else is capable of harbouring those mischievous and
secret Messengers, as the Poet[41] takes Notice.

Quo proprior quisq; est, servitq; fidelius agro


In partem Lethi citius venit.——

T H E Histories of Physick abound with Relations of Pestilences


from no other Cause than what arises from the Importation of the
Disease, if it may be so termed, from distant Countries; and
sometimes not by Persons themselves distempered, but by the
Conveyance of these Pestilential Miasmas in their Cloaths or Wares
imported in the Way of Trade. Fracastorius,[42] an eminent Italian
Physician, tells us, That in the Year Fifteen Hundred and Eleven,
when the Germans were in Possession of Verona, there arose a
deadly Disease amongst the Soldiers from the Wearing only a Coat
purchased for a small Value; for it was observed, that every Owner
of it soon sickened and died; until, at last, the Cause was so
manifestly from some Infection in the Coat, that it was ordered to be
burned. Ten Thousand Persons, he says, were computed to fall by
this Plague before it ceased.

F R O M the same Cause, that is, infected Garments, and


Merchandize, Mercurialis takes Notice of a Plague in his Time at
Venice; and Appianus Alexandrinus[43] assures us, that the Celtæ,
after a Conquest over the Illyrici, and in Possession of their Plunder,
were infected with a grievous Plague, which the Illyrici then laboured
under. Thycidides also, in his Relation of the Plague at Athens,
intimates, That it was brought from some Part of Ethiopia by the like
Means. And Prosper Alpinus[44], before mentioned, seems to lay the
greatest Stress for the Frequency of the Plague at Grand Cairo, to
the Traffick with those Countries as are hardly ever free from
Pestilential Diseases. A great many Physicians have charged the
Plague in Sixteen hundred and sixty three at Amsterdam, to the
Infection of some Pestilential Miasms which were transported from
Smyrna and Algiers, then much infected with such Diseases, with
some Merchandize; by which Means likewise it was conjectured soon
afterwards to reach London, and several other Parts of England, as it
appears from the preceding Account of Dr. Hodges. To this Purpose I
remember to have read a strange Story, somewhere in Baker’s
Chronicle, of a great Rot amongst Sheep, which was not quite rooted
out until about Fourteen Years Time, that was brought into England
by a Sheep bought for its uncommon Largeness, in a Country then
infected with the same Distemper: And upon this Account it is that
the Prudence of those Nations and States are to be justified, who
enjoin all Persons and Merchandize from infected Countries, to stay
a certain Time upon their Coasts and Borders before they are
suffered to intermix with a healthful People; having by such
Instances as here mentioned been justly alarmed at the
Incroachment of such dreadful Destroyers.

T H E S E Historical Fragments are put together, in Order to


apprize those Readers who have not been very conversant with
Things of this Kind, with the various Ways by which the most
dangerous Diseases, and even sudden Death, may be introduced
into our Constitutions, by the Agency of very minute and unheeded
Causes; and likewise the better to support the Distinction necessary
to be made between Epidemic Diseases, and a Contagion; as well as
to illustrate the Manner whereby the latter subsists, spreads, and
proves fatal, when the Causes producing the former are absent.

Epidemic Diseases of all Kinds and Degrees of Exacerbation,


have their Rise from some common Cause, that affects all within its
Extent more or less, in Proportion to the particular Fitness of
different Constitutions to be affected by it: And by the Bellinian
Doctrine we are taught, how all those Changes are made in the
Blood, when thrown into a Fever by these Causes, even from the
most simple Ephemera, to the most complicated and malignant
Cases whatsoever; to which therefore the Reader must be referred,
for a clear Understanding of such Matters; it being sufficient to our
Purpose here to observe, that he demonstrates all Fevers to be
attended with some Fault in the Blood’s Motion, Quantity, or Quality,
or in some or all of them together; and that its chief Fault in Quality,
(which is most to the present Case) consists in an unequable
Fluidity, some Parts of it being rendered thinner, and others thicker
at the same Time, than in a natural State; not unlike what happens
to all coagulated Liquors.
F R O M this Condition of Blood, this great and wonderful Man
goes on to shew, through the whole Course of his Propositions, that
the coagulated Part, which he commonly distinguishes by the Name
of Lentor, does accumulate in the capillary Vessels until their
Endeavours of Restitution, as in all Elastick Bodies, are greater than
the protruding Force, when by the Arteries Re-action upon it, the
Lentor is shook, dislodged, and washed away into the Veins, and
ordinary Course of Circulation, there continuing its Progress till it is
either fitted for some Secretion and Evacuation, or again lodged in
the Capillaries, to bring on a new Paroxysm.
T H I S unequable Fluxility of the Blood arises from two general
Causes, either from such Means as diminish its Motion, or from the
Mixture of such Particles, as cannot only of themselves be reduced
by the digestive Powers into homogeneous Dispositions therewith; or
as have a Faculty to put in Fusion some Parts of the Mass, and leave
the other thicker than before; these are particularly enumerated,
and their Ways of Operation distinctly demonstrated by Bellini.

C O N F O R M A B L E to this Change in the Blood, which is the


common Promptuary of all the other animal Fluids, every Thing
separated from it hath some correspondent Affections; and the
nervous Fluid in particular, which is separated from a Mass so
unequally fluid, cannot but in it self have some Parts too fine, and
others too gross, besides the Inequalities in the Times and
Quantities of its Separation; from all which the same Author
accounts for those Affections, termed nervous, which are the
Concomitants of Fevers: And in the Prosecution hereof he frequently
takes Occasion to speak of this Fluid to be thin, sharp, hot, fiery, dry,
&c. as the saline and rigid Parts in its Composition are by the
Distemper more or less subtilized, or more or less defrauded of its
humid Parts by Exhalation.
F U R T H E R M O R E , in this great Disorder of the Constitution,
and inordinate Hurry and Colluctation of the Fluids, sometimes the
Solids are maintained in their Contractions and Motions, until the
Particles either introduced from Abroad, or generated in the Body,
which cannot be assimulated into homogeneous Qualities, are
thrown out of the Course of Circulation by the natural Discharges, by
Transpiration, or by Abcesces; and the animal Fluids restored to their
natural State. But when Matters are brought to this pass, it happens
that the very Means of saving one Person, may prove the
Destruction of many others; because what is thus critically thrown
off by one, hath a Faculty of exciting the like Disorders in the Fluids
of another, when it is insinuated into them; as a very small Quantity
of some fermenting Substances will communicate its Efficacies a
very great Way, and put very great Parcels of Fluid into the like
Agitation. And this is the Way by which a malignant Fever comes to
be infectious, and a Pestilence changes into a Contagion; as Bellini
more largely explains it in his XXVIIIth Proposition of Fevers; from
the whole of which it is manifest, as Dr. Mead hath expressed it in
his fifth Essay of Poisons, that the Effects of the one are the Cause
and Beginning of the other.
T O bring then this nearer to the Matter under Examination, the
Plague which is described in the foregoing Pages, was strictly and
properly a Contagion, and by all Accounts of the best Authority, That
which hath made such vast Devastations in some Parts of France,
and now continues to rage amongst them, to the great Terror of
their Neighbours, is also of the same Kind; and was brought to them
in Merchandize, and by a Ship’s Crew, who were sick of a pestilential
Disease all their Voyage Home from some Parts of Turkey; in neither
of these there being any Manner of Fault chargeable upon the Air, or
to any other Causes before enumerated in producing a Pestilence.
T H E Symptoms of That now Abroad are reported by the best
Physicians amongst them to be sudden Pains in the Head, great
Loathing at Stomach, Reaching to Vomit, Consternation, wild Looks,
trembling Voice, Coldness in the extreme Parts, low unequal Pulse,
Paleness, Delirium, Convulsions, Carbuncles, Buboes, livid
Vesications, purple Spots, and Hemorrhages; the last are certain
Forerunners of Death. All which, more or less, are the constant
Attendants of all pestilential Fevers.
B E C A U S E then there is such a vast Difference between a
Pestilence arising from assignable Causes in the Air, &c. and a
Pestilence from a Contagion, as to the preservative Means especially
against them; and that what we are now in most Apprehension of, is
of the latter Kind; it most concerns us to be well acquainted with the
Manner of Infection, as far as we can reason about Agents so
extreamly minute and subtle. How all other Antecedents to a
Pestilence exert themselves in their Influences over the animal
OEconomy, Bellini has brought even to a Demonstration; but as to a
Contagion, he says little; which therefore, as introductory to some
following Remarks, we shall here insert.
‘As this Coagulation and Fusion may go on so far as to set at
Liberty, and perspire through the Surface of the Body, or with the
Breath in Respiration, many noxious Particles, which may be so subtil
and active, as to enter the cutaneous Pores of other Persons, or mix
with that Air which they draw in Respiration, and when got into the
Body, be able to make the same Change in the Blood, both as to its
Coagulation and Fusion; hence it comes that such a Fever proves
contagious, which is an inseparable Requisite to a pestilential Fever.
‘But this is not only thus brought about; but also the dissolved,
and dispersed Particles may longer adhere to some inanimate Bodies
than others, as to Woollen and Linen Cloaths, Papers, &c. and these
Particles may, by the Steam of a living Body, or by the Means of any
other Heat, be put into Motion, so as to breath out of those
Lodgments, where they quietly resided, and obtain so much Liberty,
and Action on all sides, as will carry them into the cutaneous Pores
of any Persons within their Reach, and infect them; and on this
Account a Pestilence may be brought from very distant Countries,
lying a long Time in such Manner concealed, and then suddenly
breaking out; with many other Circumstances of like Nature.
‘B U T if these subtile and active Particles be of that Nature, that
they can penetrate the Pores of other Animals, and occasion a like
Coagulation of their Blood, not only Men, but Brutes also, will be
seized with a Pestilence; but this does not always very necessarily
happen; because the Blood of Animals is different from humane
Blood, so that although these Particles are supposed to get into it, it
does not therefore necessarily follow that they must vitiate it, any
more than will Aqua Regia dissolve all kinds of Metals; but yet Brutes
of all kinds, or some of them only, will be seized equally with Men,
when this subtile and active Ferment, which penetrates the Surface,
is of that Nature, as will taint the Blood of other Animals with those
pestilential Requisites.
‘A S this kind of Contagion then can easily proceed from an
infected Person at a great Distance, as often as the noxious Particles
can reach another Person, and give that Degree of Coagulation and
Fusion, as is necessary to a Pestilence; the more aggravated then
will be this Calamity, and more easily spread, when a healthful
Person is near to one already infected; and yet much more worse, if
it is in Contact with those Parts, which more plentifully, and with a
greater Impetus, breath out infected Steams, as if the Air arising
from the Mouth and Lungs, which must be extreamly hot, or the
Perspiration of a Carbuncle when it is greatly inflamed; for in this
Case the exhaling Particles will be in their greatest Activity when
nearest the recipient Body, and likewise more dense, that is, more
numerous, and consequently of greatest Efficacy.
‘B U T it is not every one that is seized with a Pestilence from
Contagion, by Means of Steams exhaling from any particular Parts of
the Body; but only when these Steams, and the Air it self, hath
joined with, and interspersed through it Particles of vitiated
Faculties; and then this Kind of Fever will easily be communicated,
and necessarily ensue, not only on Account of what gets into the
Body with the inspired Air, but because also the whole Body is
surrounded with such an Infection, wherein the noxious Particles
floating about on all Sides, will endeavour to penetrate through the
Pores upon the Surface, and get that Way into the Blood; for
although the Skin is thicker upon the Surface of the Body, than that
Pellicle covering the Vessels in the Lungs, and for that Reason it
requires longer Time for such Particles to get that Way into the
Blood, and the Habit of the Body, yet it is no Argument that they
cannot get that Way at all, and be admitted into the Juices.’
B Y this we are able to gather, that when a Fever from some
Faults in the Non-naturals comes to the highest Degree of Malignity,
it makes such a Change in the animal Fluids as renders some Parts
of them poisonous, and capable of exciting the like fermentative
Motions, wheresoever they come into a proper Subject, without any
of those procatarctic Causes as gave Rise to the Fever of the first
Person seized.
O F what Nature then this Poison is we may conjecture from the
Circumstances of its Production. All animal Bodies do more or less
generate a Salt; or rather, in Proportion to the Strength of their
digestive Powers, do they more or less subtilize the saline Particles
which are taken in with their necessary Nourishment. This is
abundantly manifest in the Distillation of many animal Substances,
which plentifully yield a volatile Salt. But indeed in the Composition
of this, in a natural and healthful State, there is joined a very
subtilized Sulphur or Oil; which contempers and softens it into a
Fitness for the Purposes of the OEconomy: And under this
Modification, it becomes the Principle of Vitality, and the chief
Instrument of animal Action; not unlike what this is conceived to be,
is the common Sal volatile oleosum, or any other Spirits drawn from
odorous Bodies.
I T matters not what Names Persons please to distinguish this
by, in an humane Body; but that somewhat of this Kind is naturally
the Produce of its digestive Powers, in the highest Degree of
Comminution or Subtilization they are capable of bringing any Thing
to, no one will question; and that those minute Threads or Fibres, of
which the whole is a Composition, are animated by it; or, to speak
more strictly, owe to it their Elasticity and motive Faculties.
I T is hoped, that no one who hath been accustomed to
Reasonings of this Nature, will find any Difficulty in conceiving such
a Difference of Principles, so finely blended together, as here
suggested of a saline, and an oleous, or humid Substance: And
whosoever reads Bellini, or any others who have wrote in the same
Manner, will find continual Regard had to those two Principles, even
in the animal Spirits; for without it there can be no Notion had of
what is so frequently mentioned, and which by their Effects we find
must be true of them, that they are too dry, hot, active, fiery, and
the like; or too humid, vapid, sluggish, viscid, &c. And it is further
equally manifest, that in Proportion to the greater or lesser Degrees
of Motion in those Fluids, from whence this subtile Composition is
generated, and the Concussions of those fine Threads into which it is
separated, will it err in one or other of the foregoing Extremes.

I N a Fever therefore, where the animal Fluids are in the highest


Degree of Agitation, and from Causes too of a coagulating Nature, it
ought to be no Wonder that even this subtile Union should be in
some Measure dissolved, and the softer and more humid Parts broke
and exhaled, so much as to leave the more rigid and saline ones not
only unfit to lubricate those Elastick Threads, wherein they reside,
but sharp and pointed enough to stimulate, contract, and harden
them into all Loss of Motion.

A S the Destruction likewise of this Nexus in so subtile a Fluid


leaves the saline Parts capable of injuring even that OEconomy
which gave it Existence, so may its Volatility favour its Escape in a
great Measure by Transpiration, so as to affect also other Persons
within its Reach; and These with all other Particles of like Nature,
which, by an Over-Agitation, and fermentative Motion of the animal
Fluids, are separated from the softer and lubricating Compositions
with which they were naturally joined, and which by their Volatility
transpire and float in the Air, we take to be the true contagious
Miasmata, that convey, propagate, and continue a Pestilence, after
the Cause first raising it ceases.
N O R will this seem strange to any who are accustomed to
reflect, how many Substances are changeable into a poisonous
Nature, which before were not only inoffensive, but useful to the
Purposes of Life. Some Minerals, whose saline Parts in their
Production are naturally blended with good Quantities of Sulphur, are
harmless, and good Alterants; but when by any Means those
Principles are separated, the saline Parts become strong Emeticks
and Catharticks, even to the Degree of a Poison. Who does not know
that Antimony may be taken crude in large Quantities without any
manifest Effect, but that the Chymist can take somewhat from it,
that in few Grains shall operate beyond the Power of a strong
Constitution to bear?
T H O S E Arrows of Death therefore that make such dreadful
Slaughter in a Contagion, are the animal Salts of infected Persons,
set loose from their natural Combinations, and subtilized into the
highest Degree of Volatility, by the Agitation and fermentative Motion
of a Fever. And the Buboes, Carbuncles, &c. in a Pestilence, are
nothing else but Collections of Particles, or Coalescences, formed in
such irregular Motions, and thrown out of the Course of Circulation
by those necessary Laws whereby every Thing is rejected, that
cannot be assimilated into homogeneous and like Properties: The
Matter of which Excretions is likewise of so subtile and fermenting a
Nature, that if introduced into the Fluids of another well Person, it
excites there the same Motion and Disorder.
T H I S change of animal Substances into a Poison, is too
common a Truth to want any Attestation to those who have been
but indifferently conversant in Natural Enquiries. And it is greatly to
our Purpose, that even those Creatures, which are generally deemed
poisonous, do require certain Degrees of Heat, and animal Action, to
exalt their Juices to so high a Degree of Volatility, as to put on the
Properties of a Poison, and act as such upon other living Creatures;
insomuch that it is not only a common Observation that these
Animals lose their poisonous Nature when remov’d into Climes colder
than what is natural to them, but that also they are not so
venomous in their own Climates, at the cooler Seasons of the Year,
as in the most sultry.
B U T the Case of a mad Dog entirely comes up to that of a
Contagion from a Fever. When the hotter Seasons of the Year throw
that Creature into Madness, it is manifestly from a great Increase of
Velocity and Motion in the Fluids, which brings on what is equivalent
to a Delirium, by an additional Impetus upon the Brain, and for want
of so much Room through the Skin for Transpiration, as in other
Animals; the chief Evacuation is by the Glands of the Mouth: That is,
in short, the Dog hath a Fever, which breaks the natural Texture of
the Juices, disengages and subtilizes the more rigid or saline Parts,
and critically discharges them by the most convenient Outlets the
Creature is furnished with, changed into such a poisonous Nature,
that wheresoever they come to mix with the Juices of others, they
excite in them the like inordinate and mischievous Alterations.
T H I S Theory likewise might be further illustrated by many
Instances from inanimated Fluids, which are capable of being put
into Fermentation by a very small Portion of Matter, and which shall
by such an Agitation from new Particles, or Moleculæ having
Properties of communicating the same Effects to another quiescent
Fluid; not much unlike what we see in the Communication and
Propagation of Fire, which is excited and carried on in proper
Subjects from the minutest Beginnings, and increasing also in its
own Force as it spreads.
W H E N a Person therefore falls into a Fever from any epidemic,
or other more private Cause, and that Fever rises to such a Degree
of Malignity as is always supposed in a Pestilence, as far as any
Effluvia do exhale from that Person, so far may he be said to have
round him a contagious and poisonous Atmosphere; because there
transpires from him such Particles as will excite in other Animals of
like Constitution, the same fermentative Motions as those to which
they owe their own Origin.
A L T H O U G H therefore, in the Beginning of epidemical
Diseases, and during the Subsistence of their common Causes,
particular Regard is to be had to these Causes, and the Manner
whereby they affect the People; yet when it is come to this pass,
that the Fever it self is productive of a Poison, or somewhat intirely
disagreeable, that communicates the same Impressions upon others,
without any Concurrence of the first Cause, then such a Fever is
truly a Pestilence by Contagion, and all precautionary Regards ought
peculiarly to be suited, to prevent its Infection or Spreading; either
by keeping the well Subjects clear from the sick, or destroying the
Influence of the poisonous Exhalations, or fortifying the sound
against it. But to these Ends, it is necessary to have some tolerable
Notion of the Manner how these secret Destroyers are continued,
and conveyed to great Distances.
T H E most common Manner of conveying and spreading a
Contagion, observable in the preceding historical Collections, and
which also is the Case of our present Apprehensions from Abroad, is
by infected Persons, and Merchandize; it being attested by too many
Facts to admit of the least Doubt, that even Packs and Bails of
Goods carry the poisonous Miasmata about with them; and from the
Nature that we here suppose this Poison to be of, nothing is more
likely to preserve it than animal Substances, as Hair, Wool, Leather,
Skins, &c. because the very Manner of its Production, and the Nature
of its Origin, seems to give it a greater Affinity with such Substances
than any other, and to dispose it to rest therein until by Warmth, or
any other Means of Dislodgement, it is put into Motion, and raised
again into the ambient Air.
T O know how these Effluvia come to have such fatal Influences
over Mankind, and to understand their Progression from the first
Seizure, to the End of that Distemper they gave Birth to, requires
too many Precognita from the Mechanism of the animal OEconomy,
and the Agency of such minute Instruments, to be particular about,
in the Compass here limited. And a Reader who is duly fitted for
such Enquiries, will find the utmost Satisfaction from Bellini of
Fevers, and Dr. Mead of Poisons; how the Blood, and all the
Secretions therefrom, are affected, and changed by such Causes.
W E shall here therefore only suggest some Hints concerning
the Suddenness of their Seizure, and their Energy of Operation. And
this will not be difficult to conceive by those who are acquainted
with that universal Property of Matter, whereby it is more or less
determined to draw, and unite again, when separated into Parcels,
according to the greater or lesser Affinities of their Figures,
Solidities, and Quantities of Motion. As nothing therefore in Nature is
supposed to bear a greater Similitude, than in this Case the natural
animal Salts do with what hath been subtilized and set on Float in
the Air, it can be no Wonder that when the Ambient is sated with the
latter, they readily join with the former, as soon as they are received
into the Body. And this is supported by the Authority even of Bellini,
who allows, in the Beginning of his XXVIIIth Proposition, that the
Antecedents to a pestilential Fever do sometimes vitiate the Spirits
immediately in Quality.
A S the ordinary Course therefore of producing Fevers is by
disordering the Blood first in Quality, with such Mixtures as coagulate
it, that is, as make it unequally fluid, some Parts being thinner, and
others thicker than natural; so by these extreamly subtile Effluvia, in
a Contagion, the Spirits are destroyed in their natural Texture, and
the more rigid and saline Parts, by a Combination with the
venomous Spicula, changed into Dispositions destructive of that
Constitution they were before destined to preserve. Whosoever then
considers what must be the necessary Consequences of such an
immediate Depravation and Change in that Fluid, which is an
absolute Requisite to all animal Action, will not at all wonder at any
of the Affections which are commonly enumerated as the
Concomitants of a Contagion; and a tolerable Acquaintance with the
OEconomy, by the Help especially of the Authors before referred to
on Fevers and Poisons, will enable any one to account severally for
their Production.
T H I S then being the Case of a Contagion, that a Person
having a Fever, critically throws off poisonous Effluvia, which were
generated during such irregular Motions of the animal Fluids,
insomuch as to diffuse for some Distance round, what will infect
other Persons within their reach; and that so many have got this
Infection, that no Part of the Air, for some Tract of the Country
together, is free from them; the poisonous Atmospheres, if they may
be so termed, of the infected, extending and mixing into one
universal, common Contagion; this, I say, being the Case here under
Examination, why any at all survive, must be owing either to the
Goodness of their Constitution, or to proper Means to defend against
its Infection, or to conquer it when received; which naturally brings
us to consider these two important Ends, of Preservation and Cure.
A S for the First of these, the common Experience, of meaner
People being mostly carried off, admonishes all to live upon as
nutritive and generous a Diet as can be procured; and such Things
as not only yeild due Nourishment, but Plenty of Spirits, and what
easily perspires. For there are many Things of good Nourishment,
that are not easily perspired; such as all light and viscid Substances,
as Pork, Fish, and the like, which therefore are very apt to go into
Fermentation, and generate Corruption; in short, whatever even the
common People have Notions of, as apt to bring Surfeits, ought to
be avoided, and such Means of Subsistance complied with, as
generate a warm, rich Blood; and in Proportion to the Ways of Living
at other Times, should every one, except those who accustom
themselves to Riot and Excess, indulge himself at a higher Rate.
R O A S T E D Meats are by all preferred to boiled, and if Pickles
and high Sauces are ever to be encouraged, it is on these Occasions;
and Garlick, Shallot, Onions, &c. are extreamly serviceable, and
preferable to the hot, dry, spicy Seasonings, because their pungent
Volatility seems naturally covered with a Softness, or balsamick
Quality, more agreeable to the Nature of animal Spirits. To which
Purpose it is very remarkable, that in the Histories of many
Pestilences, Notice is frequently taken of the Exemption of Jews, and
People who deal much in such Fare, from Infection. And it is
customary with some experienced Sailors, to lay in great Stores of
such Things against their Arrival at infected, and unwholsome
Countries.
T H E R E is also a very strict Regard to be had to the Firmness
and Strength of the Solids, which is greatly assisted by moderate
Exercises, but carefully avoiding too much, and every Thing that
occasions too great an Expence of Spirits at a Time, and particularly
by over-Warmth. But to this Purpose I cannot conceive any Thing
more serviceable than frequent Immersion in cold Water, so that the
Times of staying in are as short as possible, the Good received
hereby being chiefly in the first Shudder and Constriction; and it is
particularly to be remembred, tho’ the preceding Author hath
omitted it, that Watermen, and others, whose Occasions imployed
them much upon the River, and in the Cold, suffered least in the late
Sickness. The Use of Vinegar, and other Acids, are also of Service for
the like Intention.
Y E T besides the Helps for this End from common Diet, and
Way of Living, Assistances may also be had from Medicinal
Preservatives, such as those commonly termed Antidotes, consisting
of spicy volatile Particles, which afford a natural Pabulum to the
animal Spirits, and by carrying into the whole Habit a fine subtle Oil,
the better secure them against those Contagions Spicula which are
in Readiness to mix with them; and for this Purpose, we are
furnished with a most elegant and useful Medicine, since many
Authors of Note have wrote on this Subject, which is the Sal Volatile
Oleosum, if it be well loaded with the essential Oils of Spicy
Ingredients; although indeed with some Constitutions more fetid
Compositions are very suitable; but they all agree in carrying into
the Habit somewhat that both recruits, and guards the Spirits
against any foreign Mixture, or from unnatural Separations of their
saline and humid Parts. And to the same End, in robust
Constitutions, who have been accustomed to fare hard, the Spirit or
Oil of Turpentine frequently drank in small Doses might be a great
Means to preserve the poorer Sort from Infection.
B E C A U S E former Writers on these Occasions have given
Formulæ of things of this kind, much more prolix and inelegant than
the present Practice is accustomed to, it may not perhaps be
unacceptable to give two or three Examples more conformable to
the latter. But because I judge such general Prescriptions rather of
Prejudice than Service, when they come hastily and inadvertently to
be required by the common People, I cannot but think it much better
to leave such to be ordered and regulated according to particular
Persons Constitutions and Exigencies.
A S to those preservative Means which a Government only have
the Power to provide, they must likewise be left to those who have
that Power, but, with due Submission to such, it is conceived that
removing infected Persons is a much easier and safer Care, than
shutting them up in great Towns: And it was certainly the greatest
Error committed in the late Plague here, as our Author above
grievously complains, to confine the sick and well together.
I T seems a Point yet in Dispute, whether great Fires at such a
Time are of Service or hurtful, which to me is somewhat wonderful,
because whosoever considers the Necessity for Air in Respiration,
and by what Quality it becomes of such real Service to the
Preservation of Life, cannot think such Fires proper, because they
destroy that very Property in the Air, which is demonstrable by
innumerable Experiments. As to the Dissipation indeed of pestilential
Vapours, or their Destruction in any Manner, they undoubtedly may
do Service, but then that ought to be done at vast Distances only
from where People inhabit. And what Fires common Occasions
require at such Times, are rather to be made with such Substances
as abound with, and yield a nitrous Salt, because that seems to be
the chief Support of the vital Property in the Air, and such are our
common Coals; for every one knows how much more all Wood-Fires
are suffocating, and give a Languor, and Flatness to the Spirits.
P R E S E R V A T I V E Fumigations are largely talked of by all, on
these Occasions, and they with good Reason deserve to be
practised, because while the Poison is on Float in the Air, it may
undoubtedly be entangled so as to lose its Power of acting as such;
but then for this Purpose such Things ought to be used as exhale
very subtile Sulphurs, as the spicy Drugs and Gums. And on this
Account I suspect Wood-Fires to be bad, because they raise into the
Air a very gross and viscid Humidity, which is not only very unfit to
lay hold on, and unite with, the extreamly minute Agents that are to
be provided against, but also carry into the Lungs with the Air in
Respiration, such Particles, as dispose of themselves to Viscidities,
and such Changes in the Blood, as are the Production of the worst
Fevers, without any other co-operating Cause; for the Fire only
forces out that Moisture, which, while a Tree is in its Growth,
naturally perspires from it; and how an Air so impregnated is like to
be of Service against a Pestilence, any one may soon be a Judge,
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like