List of Figures

Chapter 1. Welcome to Node.js

Figure 1.1. Asynchronous and nonblocking components in a Node application

Figure 1.2. The event loop

Figure 1.3. Node’s software stack

Chapter 2. Node programming fundamentals

Figure 2.1. Navigating your code is easier if you organize it into directories and separate files rather than keeping your application in one long file.

Figure 2.2. The population of the module.exports property or the exports object allows a module to select what should be shared with the application.

Figure 2.3. Node modules can be created by using either files (example 1) or directories (example 2).

Figure 2.4. When you put ./ at the beginning of a module require, Node will look in the same directory as the program file being executed.

Figure 2.5. Steps to finding a module

Figure 2.6. The package.json file, when placed in a module directory, allows you to define your module by using a file other than index.js.

Figure 2.7. Shared app object in a web app

Figure 2.8. An HTML response from a web server that pulls titles from a JSON file and returns results as a web page

Figure 2.9. An echo server repeating the data sent to it

Figure 2.10. Serial execution of asynchronous tasks is similar, conceptually, to synchronous logic: tasks are executed in sequence. Parallel tasks, however, don’t have to execute one after another.

Figure 2.11. How serial flow control works

Figure 2.12. Using parallel flow control to implement a frequency count of word use in numerous files

Chapter 3. What is a Node web application?

Figure 3.1. A read-it-later web application

Chapter 4. Front-end build systems

Figure 4.1. Two build processes that share functionality

Figure 4.2. Sample gulp-help output

Chapter 5. Server-side frameworks

Figure 5.1. Koa middleware execution order

Figure 5.2. LoopBack’s project generator

Figure 5.3. The StrongLoop API explorer showing User routes

Figure 5.4. Choosing a Node framework

Chapter 6. Connect and Express in depth

Figure 6.1. The life cycle of two HTTP requests making their way through a Connect server

Figure 6.2. Middleware ordering is important.

Figure 6.3. The life cycle of an HTTP request causing an error in a Connect server

Figure 6.4. Default application skeleton structure using EJS templates

Figure 6.5. Express help

Figure 6.6. Generated package.json contents

Figure 6.7. Default Express application

Figure 6.8. HTML template plus data = HTML view of data

Figure 6.9. The view cache setting

Figure 6.10. Express view lookup process

Figure 6.11. Values passed directly to the render function take precedence when rendering a template.

Figure 6.12. User registration form

Figure 6.13. Registration form error reporting

Figure 6.14. User login form

Figure 6.15. User login and registration menu used to access the forms you created

Figure 6.16. Menu when the user is authenticated

Chapter 7. Web application templating

Figure 7.1. The flow of an MVC application and its interaction with the template layer

Figure 7.2. Example blog application browser output

Figure 7.3. Pug’s include mechanism provides a simple way to include the contents of one template in another template during rendering.

Chapter 8. Storing application data

Figure 8.1. Knex’s usage statistics

Figure 8.2. MongoDB’s usage statistics

Figure 8.3. The redis package’s statistics on npm

Figure 8.4. Redis channels provide an easy solution to a common data-delivery scenario.

Figure 8.5. The levelup package’s statistics on npm

Figure 8.6. Examples of third-party LevelDB packages on npm

Chapter 9. Testing Node applications

Figure 9.1. Test framework overview

Figure 9.2. Failing test in Mocha

Figure 9.3. Successful test in Mocha

Figure 9.4. Vows can structure tests in a suite using batches, contexts, topics, and vows.

Figure 9.5. Vows combines full-featured BDD testing with macros and flow control.

Figure 9.6. Testing with browser automation

Figure 9.7. Using wdio to configure Selenium tests

Figure 9.8. Running an Express application with DEBUG='*'

Chapter 10. Deploying Node applications and maintaining uptime

Figure 10.1. The Forever tool helps you keep your application running, even if it crashes.

Figure 10.2. A master spawning three workers on a four-core processor

Figure 10.3. You can use Nginx as a proxy to relay static assets quickly back to web clients.

Chapter 11. Writing command-line applications

Figure 11.1. Node’s argv compared to yargs

Figure 11.2. Combining pipes and output streams

Chapter 12. Conquering the desktop with Electron

Figure 12.1. Visual Studio Code’s application window and a native context menu

Figure 12.2. The main parts of a typical Electron application

Figure 12.3. The electron-quick-start project running in macOS

Figure 12.4. The HTTP Master Electron application

Figure 12.5. A desktop notification

Figure 12.6. A typical Electron application bundle’s contents

Appendix A. Installing Node

Figure A.1. The installer .pkg file

Figure A.2. The installation wizard

Figure A.3. Node’s REPL

Figure A.4. The Windows .msi installer

Figure A.5. Node’s REPL in Windows

Appendix B. Automating the web with scraping

Figure B.1. Steps for scraping and storing content

Figure B.2. Octopart allows users to search for electronic parts.

Figure B.3. Scraping with cheerio

Figure B.4. Viewing HTML in Chrome

Figure B.5. Scraping with jsdom

Appendix C. Connect’s officially supported middleware

Figure C.1. How a form is processed by body-parser

Figure C.2. A favicon

Figure C.3. Using methodoverride to simulate a PUT request to update a form in the browser

Figure C.4. Basic authentication prompt

Figure C.5. The default errorhandler HTML as displayed in a web browser

Figure C.6. Serving directory listings with Connect’s directory() middleware component