2 Getting started with Node.js

 

This chapter covers

  • Installing Node.js and creating a project
  • Creating a command-line application
  • Creating a reusable code library
  • Creating a simple web server with a REST API
  • Reviewing a primer on asynchronous programming and promises

In this book we’ll use Node.js often, and this chapter will help you become productive with it. You’ll learn fundamentals of creating projects and applications with Node.js. We’ll only cover the basics, but we’ll cover enough for you to use Node.js for the rest of the book.

Toward the end of this chapter there’s a primer on asynchronous programming and promises. This is more advanced, but you’ll need it because Node.js and JavaScript in general rely heavily on the use of asynchronous coding.

If you already have experience with Node.js and asynchronous coding, then you might want to skip most of this chapter and move directly to chapter 3. First, though, please at least read the sections “Starting your toolkit” and “Getting the code and data” before you move on.

2.1 Starting your toolkit

A core theme of this book is building out our data-wrangling toolkit as we learn. We’ll start developing our toolkit in this chapter and continue to expand it as we go. Table 2.1 lists the tools that are introduced in this chapter.

2.2 Building a simple reporting system

2.3 Getting the code and data

2.3.1 Viewing the code

2.3.2 Downloading the code

2.3.3 Installing Node.js

2.3.4 Installing dependencies

2.3.5 Running Node.js code

2.3.6 Running a web application

2.3.7 Getting the data

2.3.8 Getting the code for chapter 2

2.4 Installing Node.js

2.4.1 Checking your Node.js version

2.5 Working with Node.js

2.5.1 Creating a Node.js project

2.5.2 Creating a command-line application

2.5.3 Creating a code library

2.5.4 Creating a simple web server

2.6 Asynchronous coding

2.6.1 Loading a single file

2.6.2 Loading multiple files

2.6.3 Error handling

2.6.4 Asynchronous coding with promises

2.6.5 Wrapping asynchronous operations in promises

2.6.6 Async coding with “async” and “await”

Summary