This course has been updated! We now recommend you take the Introduction to Node.js, v2 course.
Table of Contents
Introduction
Course Overview
Scott Moss introduces himself, the course repository, and sets the agenda for the day of starting with Node.js basics, then introducing topics until a server is deployed.What is Node.js
Scott defines Node.js as an environment for running JavaScript outside the browser. What that means in context, as well as what design decisons were made are discussed.Creating with Node.js
Scott gives an overview of use cases when creating apps with Nodejs.Installing Node.js
Scott describes installing node using both from Nodejs source, and using NVM. Scott explains several costs and benefits of each, and why NVM is the preferred method.Running Node.js Code
Scott demonstrates how to run a JavaScript program using the Node.js CLI executable or REPL.Installing Node.js from the source
Scott demonstrates how to download Nodejs without the aid of NVM.Installing Node.js with NVM
Scott gives instruction on the recommended way to download Node js using nvm.Install and Run Node.js Exercise
Scott introduces the first exercise: getting Node.js installed!Checking Install & Running Node.js Solution
Scott troubleshoots some common issues with Node.js installation, and demonstrates how to execute a file.
Node.js Modules
Browser JavaScript vs Node.js
Scott introduces several key differences between Node.js and JavaScript in the browser, including the presence of the DOM, fragmentation, and access to the local filesystem.Globals in Node.js
Scott gives an overview of process, require, __dirname, module, and global, that are all global variables provided to apps by Node.js.Node.js Modules
Scott introduces what Node modules are, and recommends ESM as it is the newest standard. This course will be using CommonJS.Creating Node Modules
Scott demonstrates a pattern for Commonjs exports while explaining the difference between default and named exports, coaches on the importance of explicit exports, and advises against using the exports global.Importing Node Modules
Scott demonstrates how to use the require keyword to import node modules. It's specifically detailed how to require modules that are user-created.Q&A: ES Modules & Latest JS Features
Scott fields questions about ES modules in the browser, using Webpack in Nodejs, whether Nodejs will attempt to support all new JavaScript features, and Scott's VSCode theme.Convert Browser JavaScript Exercise
Scott directs students to complete an exercise using the Jest testing suite to convert prewritten browser code to Node.Convert Browser JavaScript Solution
In addition to going over the solution, Scott also answers questions about the testing suite being utilized, and the style choices for the exercise solution.
Internal Modules & npm
The fs Module
Scott walks through several examples of how to read and write to files using the fs Module that is shipped with Node js.Other Internal Node Modules
Scott briefly speaks to the http module, then moves on to talk about the path module that normalizes paths for the user, and mentions the url and crypto modules.Remote Modules
Scott introduces modules created by other people on the internet, and why it's more efficient to utilize these than writing them from scratch. The community of Node js, public modules, and malicious modules are all discussed.Modules Recap
Scott gives an overview of how to require custom local modules, remote modules, and shipped modules. Attention is given to why it's important to note if the remote module has the same name as a shipped module.npm
Scott gives an overview about how to select reputable modules, what dependencies and devDependencies are in a package.json file, how to install a single node module, and most common use cases.yarn
Scott introduces another package manager created by a different company that does similar things to npm.CLI with Node Exercise
Students are instructed to complete a program that saves and retrieves contacts from an address book.CLI with Node Solution
Scott live codes the solution to the exercise, instructs on how to add formatting to the output JSON, and discusses using path.resolve() versus path.join().commander Module for Building CLIs
Scott shows the "hack" around the process module called commander that was used to create commands, have aliases, and have a full CLI.
Asynchronous Node
Asynchronous Code in Node.js
Scott gives a quick refresher of Async JavaScript, which is used heavily in Node JS.Asynchronous Patterns
Scott gives examples of callbacks, promises, and async/awaitError Handling
Scott explains why it's imperative to handle errors in Node js.Servers
Scott introduces how servers interact with the Node js environment.Asynchronous Server Exercise
Students are instructed to refactor and fix a simple static asset server.Asynchronous Server Solution
Scott live-codes the solution to the exercise, and gets feedback from students on how they solved the exercise, and difficulties they had.
Debugging & Testing
Debugging Node
Scott explains the three paths to debugging, including using logs, using the node inspector, and utilizing text editor integration.Testing Node Libraries
Scott details how Node js has advanced to be extremely versatile over the last few iterations, and gives several use cases for testing in Node js.Anatomy of Tests
Scott gives a brief description of test suites, assertion libraries, mocks, and spies.Types of Tests
Scott defines what unit, integration, E2E, UI, snapshot, and performance testing are.Debugging & Testing Exercise
Students are directed to find and debug several issues in the app, and then implement unit tests to ensure that they stay fixed.Debugging & Testing Solution
Scott live codes the solution to the exercise using Chrome inspector, and fields a question from the audience afterwards about how to autopopulate the chrome inspector with the files. How to write the tests to test for the bugs that were caught is also briefly covered.
Publishing and Deploying
Sharing Modules
Scott details the checklist to go through to make modules sharing-ready.Deploying Your Servers
Scott details what to think about when deploying the server to a cloud provider. Questions are also answered about versions, and the difference between a static site generator and static site server.Deploying to Heroku
Scott demonstrates how to deploy the module to Heroku, and describes how to publish to npm.Further Tools & Resources
Scott gives an overview of how to take this knowledge and bring it further than this course.Final Q&A
A question is asked about CMS, and Scott wraps up the course by giving further resources and thoughts.