What this book covers
Chapter 1, Introduction to Node.js, provides an introduction to Node.js as a runtime and also explains the core architecture behind the single thread. It will also cover the versioning of Node.js and its release schedule.
Chapter 2, Setting Up the Development Environment, covers how to install Node.js on the most popular operating systems and you will learn how to manage multiple versions of Node.js on the same machine. It will also cover how to use the Node.js REPL and the web browser console to debug Node.js and JavaScript applications.
Chapter 3, JavaScript Fundamentals, helps you to refresh your knowledge of JavaScript basics such as operators and loops. You will also learn how to use specific JavaScript features such as closures, hoisiting, and prototype inherit.
Chapter 4, Asynchronous Programming, teaches you how to implement the callback pattern, handle promises, and use Async/Await syntax, and you will also learn how to properly combine all the patterns, including error handling
Chapter 5, Node.js Core Libraries, covers the core libraries’ structure including the stability index and command-line options for the Node.js binary. Also, you will learn how to modularize any code using ESM and CJS and how to combine them.
Chapter 6, External Modules and npm, covers how to use the NPM CLI to manage dependencies, and use npx to use CLI tools without adding them to your project. You will learn how to build isomorphic code that can be executed in Node.js and in the browser and you will publish your first package to npm. We will also discuss npm alternatives such as Yarn or PnPM.
Chapter 7, Event-Driven Architecture, explores how the event-driven architecture is included in many core libraries such as fs
and http
. You will create applications that react to changes in files or receive HTTP requests, and will learn how to include an event API in your own modules as an API layer.
Chapter 8, Testing in Node.js, explores how testing is done in Node.js and all the possible approaches. We will use the Core testing library and Jest to build unit tests, and will use the coverage report to understand where to improve our testing strategy. Additionally, we will explore how the Test-Driven Development (TDD) approach in practical terms.
Chapter 9, Handling HTTP and REST APIs, teaches different strategies to build a web application (such as SPAs and server-side rendering) and how HTTP is structured in a way that allows us to build modern and solid APIs (with HTTP headers, status codes, payloads, and versions). We also learn how to use te URLs to build powerful interfaces while transferring data using JSON format.
Chapter 10, Building Web Applications with Express, shows how to use Express in depth (request, response, redirections, status codes, and header management) and also covers how to use middleware libraries and built your own ones.
Chapter 11, Building a Web Application Project from Scratch, We will begin our work on our project and will build a REST API covered by tests using the supertest library. This project will evolve, so we will iterate over the project adding new features and new tests, so you can experience the full development cycle of a real world application using Node.js.
Chapter 12, Data Persistence with MongoDB, demonstrates how to set up MongoDB and how to handle secrets in Node.js (.env files and environmental variables). We will explore the ORM universe with Mongoose and will evolve the project to use MongoDB as the database solution, including tests and coverage reports.
Chapter 13, User Authentication and Authorization with Passport.js, teaches the differences between authentication and authorization, as well exploring how modern web security is built based on cryptography by covering in detail how JSON Web Tokens (JWT) work. We will also implement this with our middleware in the project, and will learn how Passport.js can be used to handle social login strategies.
Chapter 14, Error Handling in Node.js, covers how to make our applications more resilient by properly defining and handling errors of any kind. We also see how to gracefully shut down the application and avoid generating zombie processes.
Chapter 15, Securing Web Applications, explores social the impact and attack vectors for your projects. We will explore how the OWASP Top 10, Common Weakness Enumeration (CWE), and Common Vulnerabilities and Exposures (CVE) work together to evaluate risks and mitigate them in our applications. We also cover the offical Node.js security best practices and the thread model. You will have the opportunity to put all of this into practice with the project that we build together, along with exploring other ways to grow in this area by exploring the ethical hacker universe.
Chapter 16, Deploying Node.js Applications, sees us deploy our application to the public internet, emphasizing clear requirements and solution choices. We will use GitHub Actions for CI, and DigitalOcean, PM2 and MongoDB Atlas for the database
Chapter 17, Dockerizing a Node.js Application, we deploy our application to the public internet using Docker and DigitalOcean. Also we will use GitHub Actions for Continous Integration (CI). We will explore domain setup, Cloudflare SSL, and the twelve-factor app principles.
The author acknowledges the use of cutting-edge AI, such as ChatGPT, with the sole aim of enhancing the language and clarity within the book, thereby ensuring a smooth reading experience for readers. It's important to note that the content itself has been crafted by the author and edited by a professional publishing team.