About the Book
You'll start by learning how to represent an HTML document in the Document Object Model (DOM). Then, you'll combine your knowledge of the DOM and Node.js to create a web scraper for practical situations. As you read through further chapters, you'll create a Node.js-based RESTful API using the Express library for Node.js. You'll also understand how modular designs can be used for better reusability and collaboration with multiple developers on a single project. Later chapters will guide you through building unit tests, which ensure that the core functionality of your program is not affected over time. The book will also demonstrate how constructors, async/await, and events can load your applications quickly and efficiently. Finally, you'll gain useful insights into functional programming concepts such as immutability, pure functions, and higher-order functions.
About the Authors
By the end of this book, you will be able to:
- Apply the core concepts of functional programming
- Build a Node.js project that uses the Express.js library to host an API
- Create unit tests for a Node.js project to validate it
- Use the Cheerio library with Node.js to create a basic web scraper
- Develop a React interface to build processing flows
- Use callbacks as a basic way to bring control back
For the optimal experience, we recommend the following hardware configuration:
- Processor: Intel Core i5 or equivalent
- Memory: 4 GB of RAM
- Storage: 5 GB of available space
We also recommend that you have the following software installed in advance:
- Git latest version
- Node.js 10.16.3 LTS (https://nodejs.org/en/)
Code words in the text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
import function also allows you to import a subsection of a module, rather than importing the whole thing. This is one capability ES6's
import has over the Node.js
require function. SUSE"
A block of code is set as follows:
let myString = "hello"; console.log(myString.toUpperCase()); // returns HELLO console.log(myString.length); // returns 5
Installation and Setup
Before we can do awesome things with data, we need to be prepared with the most productive environment. In this short section, we will see how to do that.
Installing Node.js and npm
Installations of Node.js come with npm (Node.js's default package manager) included.
Installing Node.js on Windows:
- Find your desired version of Node.js on the official installation page at https://nodejs.org/en/download/current/.
- Ensure you select Node.js 12 (the current version).
- Ensure that you install the correct architecture for your computer system; that is, either 32-bit or 64-bit. You can find out this information in the System Properties window of your OS.
- After you download the installer, simply double-click on the file and follow the user-friendly prompts on-screen.
Installing Node.js and npm on Linux:
To install Node.js on Linux, you have a few good options:
- To install Node.js through Linux package managers on systems not detailed below, see https://nodejs.org/en/download/package-manager/.
- To install Node.js on Ubuntu, run this (more information and manual installation instructions can be found at https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions):
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs
- To install Node.js on Debian-based distributions (more information and manual installation instructions can be found at https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions):
# As root curl -sL https://deb.nodesource.com/setup_12.x | bash - apt-get install -y nodejs
- The official Node.js installation page has further installation options for some Linux systems: https://nodejs.org/en/download/current/.
Installing Node.js and npm on macOS:
Similar to Linux, you have a couple of methods for installing Node.js and npm on a Mac. To install Node.js and npm on macOS X, do the following:
- Open Terminal for Mac by pressing cmd + Spacebar, typing
terminalin the open search box, and hitting Enter.
- Install Xcode through the command line by running
- The easiest way to install Node.js and npm is using Homebrew, which is installed through the command line by running
ruby -e "$(curl -fsSL(https://raw.githubusercontent.com/Homebrew/install/master/install).
- The final step is to install Node.js and npm. On the command line, run
brew install node.
- Again, you can also install Node.js and npm via the installer available at https://nodejs.org/en/download/current/.
To install git go to https://git-scm.com/downloads and follow instructions specific to your platform.