Node.js Projects Building Real-World Web Applications and Backend APIs (Jonathan Wexler) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Jonathan Wexler

JavaScript

No Description

📄 File Format: PDF
💾 File Size: 4.3 MB
13
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
Jonathan Wexler Node.js Projects Building Real-World Web Applications and Backend APIs
📄 Page 2
ISBN: 978-1-098-17314-2 US $59.99 CAN $74.99 WEB DEVELOPMENT Whether you’re a JavaScript beginner ready to build your first backend app or a self-taught developer looking to grow beyond tutorials, Node.js Projects gives you the hands-on experience you need. Through a series of self-contained projects ranging from content aggregators to secure password managers, web scrapers, ML-backed analysis, and an AI-powered learning assistant, you’ll apply modern tools like Fastify, MongoDB, Redis, JWT, and Google’s Gemini API in practical, job-relevant ways. With each chapter, author Jonathan Wexler challenges you to think like an engineer, emphasizing architectural thinking, clean coding, and iterative design. You’ll build confidence solving real-world problems while deepening your understanding of asynchronous programming, API design, security practices, and scalable deployment patterns. • Confidently master async programming with async/await and the Node.js event loop • Effectively design scalable APIs using Fastify and modular routing patterns • Reliably manage data with the filesystem, MongoDB, and CSV output • Securely implement authentication flows with JWTs and environment-based configs • Seamlessly integrate third-party APIs like OpenAI and Google Gemini • Efficiently build real-time features with Redis, schedulers, and event-driven logic • Smoothly transition from prototype to production with modern Node.js workflows Jonathan Wexler, author of Get Programming with Node.js, combines real-world engineering experience with a passion for teaching to create practical, approachable Node.js content. Node.js Projects “Even if you’re a JavaScript novice, this book will help you quickly get up to speed in building your own server-side applications using Node.js.” Charlotte M. Ellett, C63 Industries “This is an excellent book that covers advanced Node.js concepts and techniques, and it will help you to move your work to the next level.” Pankaj Gajjar, principal solution architect at Datastax, Inc.
📄 Page 3
Jonathan Wexler Node.js Projects Building Real-World Web Applications and Backend APIs
📄 Page 4
978-1-098-17314-2 [LSI] Node.js Projects by Jonathan Wexler Copyright © 2025 Jon Wexler. All rights reserved. Published by O’Reilly Media, Inc., 141 Stony Circle, Suite 195, Santa Rosa, CA 95401. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editors: Amanda Quinn and Aaron Black Development Editor: Michele Cronin Production Editor: Gregory Hyman Copyeditor: Dwight Ramsey Proofreader: Sonia Saruba Indexer: Ellen Troutman-Zaig Cover Designer: Susan Brown Interior Designer: David Futato Cover Illustrator: Monica Kamsvaag Interior Illustrator: Kate Dullea August 2025: First Edition Revision History for the First Edition 2025-07-31: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781098173142 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Node.js Projects, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
📄 Page 5
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii 1. Introduction and Setup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Installing VS Code 1 Mac Installation 2 Windows Installation 3 Linux Installation 3 Understanding Node 4 Why Node Stands Out 5 What’s Happening Under the Hood? 5 Installing Node 5 Mac Installation 7 Windows Installation 7 Linux Installation 7 Becoming a Node Developer 8 Mastering the Craft 8 Using Fastify in This Book 10 Summary 14 2. Practical Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Your Prompt 16 Get Planning 16 Get Programming 17 Translating User Input to CSV 21 Working with External Packages 28 Summary 32 iii
📄 Page 6
3. Building a Node Web Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Your Prompt 36 Get Planning 36 Building the Application Skeleton 39 Working with Fastify 39 Adding Routes and Data 43 Building Your UI 47 Sprucing Up the UI 52 Summary 55 4. Build a Secure Local Password Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Your Prompt 58 Get Planning 58 Building a Local Command-Line Manager 59 Saving Passwords with MongoDB 68 Summary 75 5. Content Aggregation Feed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Your Prompt 78 Get Planning 78 Reading and Parsing a Feed 82 Building an Aggregator 84 Adding Custom Items to Your Aggregator 88 Summary 90 6. Library API. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Your Prompt 92 Get Planning 92 Get Programming with an API Layout 96 Adding Routes and Actions to Your App 99 Connecting a Database to Your App 105 Summary 112 7. Natural Language Processor Sentiment Analysis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Your Prompt 114 Get Planning 114 Get Programming with String Processing Packages 117 Analyzing Sentiment 123 Connecting a Database and Visualization 126 Summary 138 iv | Table of Contents
📄 Page 7
8. Marketing Mailer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Your Prompt 140 Get Planning 140 Get Programming 142 Adding a Framework for Your Mailer Service 148 Connecting a Database 153 Implementing a Marketing Pixel for Email Engagement 158 Integrating a Task Scheduler 160 Summary 163 9. Web Scraper. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Your Prompt 166 Get Planning 166 Get Programming 167 Parsing with HTML-Friendly Tools 173 Scraping Web Pages with a Headless Browser 175 Summary 180 10. App Authentication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 Your Prompt 182 Get Planning 182 Get Programming 184 Building a Login Form 188 Saving and Securing User Accounts 196 Using JWTs for API Authentication 213 Summary 218 11. Coffee Order Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Your Prompt 220 Get Planning 220 Get Programming 223 Adding a Redis Server 229 Integrating a Robust Messaging System 233 Summary 244 12. Music Label Blockchain Market. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Your Prompt 246 Get Planning 246 Get Programming 249 Coding the Blockchain 257 Running the Real-World Example 270 Summary 272 Table of Contents | v
📄 Page 8
13. Building an AI-Powered Learning Assistant with Google’s Gemini API. . . . . . . . . . . . . 273 Your Prompt 274 Get Planning 274 Get Programming 276 Customizing the AI Assistant for Learning Assistance 280 Setting Up the Fastify Server 282 Setting Up Your Database and User Authentication 285 Summary 299 A. Node Cheat Sheet and Project Initialization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 B. Setting Up Your Development Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 C. Working with Databases in Node Projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 D. Working with the Code Examples and Containerizing Projects. . . . . . . . . . . . . . . . . . 331 E. Setting Up Developer Accounts and API Credentials. . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 vi | Table of Contents
📄 Page 9
Preface When I began writing this book in 2022, I saw just how much the tech community had evolved since Get Programming with Node.js (Manning). While many founda‐ tional concepts remained, the approach to development had advanced significantly. Node.js had long passed its 10-year mark since Ryan Dahl’s initial release, and the internet was flooded with tutorials on building “simple web servers.” The truth is, most projects still rely on web servers—but the expectations for how we build and use them have changed. Today, a server isn’t just a server; it’s the centerpiece of complex, resilient, and scalable applications. Likewise, the way we use JavaScript has deepened, opening up a wide array of tools and techniques to explore. Node.js Projects is crafted to showcase these new techniques and empower you to grow as a developer by focusing on five key principles: a practical learning approach, modular learning, diverse use cases, incremental skill building, and immediate feed‐ back and gratification. Each project is designed to provide hands-on, real-world experience, enabling you to apply Node.js in modular, digestible steps. This approach not only supports gradual skill development but also ensures that each chapter deliv‐ ers a satisfying sense of accomplishment, reinforcing your growth as you progress through varied and increasingly challenging applications. Programming newcomers quickly grasp how to piece together an application, but building an app is more than code—it’s about understanding architecture and design. Each chapter places you in the role of an engineer making real-world decisions. I believe practical experience isn’t copying and pasting code but developing the mind‐ set, problem-solving skills, and communication required to build products with impact. The scope of software challenges varies: some projects unfold over months, while others involve quick, focused problem-solving. This book provides a balance, offering both bite-sized coding exercises and larger, more complex projects. This modular structure encourages you to complete sections at your own pace, allowing you to pause, shift focus, or dive into chapters that align with your interests and skill level. vii
📄 Page 10
JavaScript, and by extension Node.js, has experienced incredible growth over the past 15 years. This evolution has allowed Node.js to become a go-to tool for creating everything from high-performance web apps to real-time notification systems and video streaming platforms. Learning Node.js today means understanding a wide range of potential applications. Each chapter offers you not only technical skills but a mindset for approaching real-world scenarios you’re likely to encounter on the job. This way, you’ll develop the versatility to apply Node.js to diverse projects, enhancing both your confidence and your adaptability. You might wonder, with so many free online resources, why choose a book on Node.js? And in a world where AI tools are taking on more and more development tasks, why should an engineer devote time to deep, structured learning? It’s true that learning Node.js has become more accessible than ever, but with that accessibility comes a challenge: finding resources that simulate the thought process and structure of real-world development. Node.js Projects builds skills incrementally, guiding you toward tangible accomplishments with each project. This structured path is designed to help you gain confidence and skill with each chapter. Ultimately, I didn’t want to write “just another” Node.js book. This is a collection of the most valuable lessons and techniques I’ve encountered as the industry has evolved. My goal is to help you achieve long-term growth through incremental, satis‐ fying progress. Each chapter introduces concepts that go beyond Node.js and reflect the standards of today’s developer community. Whether it takes a week or a year to complete these projects, I’m confident that this journey will make you a stronger, more versatile engineer. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. viii | Preface
📄 Page 11
This element signifies a tip or suggestion. This element signifies a general note. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://oreil.ly/node-projects-code. If you have a technical question or a problem using the code examples, please send email to support@oreilly.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require per‐ mission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Node.js Projects by Jona‐ than Wexler (O’Reilly). Copyright 2025 Jon Wexler, 978-1-098-17314-2.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technol‐ ogy and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning Preface | ix
📄 Page 12
platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 141 Stony Circle, Suite 195 Santa Rosa, CA 95401 800-889-8969 (in the United States or Canada) 707-827-7019 (international or local) 707-829-0104 (fax) support@oreilly.com https://oreilly.com/about/contact.html We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/node-projects. For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly-media. Watch us on YouTube: https://youtube.com/oreillymedia. Acknowledgments Writing Node.js Projects has been a journey of late nights, deep debugging sessions, and real-world experiments, and it wouldn’t have been possible without the support and insight of many people. First and foremost, thank you to the team at O’Reilly for championing this book from idea to finished product. Your thoughtful guidance, editorial expertise, and commit‐ ment to quality helped shape this into something truly useful for developers at all levels. To the technical reviewers and early readers: your attention to detail, generous feed‐ back, and willingness to challenge assumptions made this book sharper and more accurate. Thank you for helping me catch bugs, unclear examples, and unnecessary complexity before they reached print. To the broader Node.js community: your open-source contributions, blog posts, Git‐ Hub discussions, and Stack Overflow threads provided inspiration, solutions, and sometimes just the reassurance that I wasn’t the only one stuck on a problem. This book is built on the ecosystem you’ve created. x | Preface
📄 Page 13
To the students, colleagues, and fellow developers I’ve worked with over the years: many of the ideas and patterns in this book were born out of our shared projects and conversations. Thank you for the collaboration and curiosity. To my family and friends: your encouragement and patience during long writing sprints kept me going. I’m deeply grateful for your support. Finally, to you, the reader: thank you for choosing this book. I hope it empowers you to build, break, fix, and create confidently with Node.js. Preface | xi
📄 Page 14
(This page has no text content)
📄 Page 15
CHAPTER 1 Introduction and Setup This chapter is your guide to setting up a development environment for Node.js. It covers the core tools needed, such as VS Code, Node.js, and Fastify, along with optional components to enhance your workflow. While tools like Fastify are more specialized, feel free to skip their setup for now and revisit those sections when they are covered in later chapters. You’ll find various installation methods explained, including using a graphical user interface (GUI), third-party tools, or binary packages. Binary installations, while sometimes precompiled, may require extra steps for extraction and configuration, making them particularly useful for servers without a graphical interface. Although the provided instructions are tailored to the tools recommended for this book, you’re welcome to use alternatives that meet your development needs. The goal is to equip you with a solid foundation to start coding and running your Node.js applications effectively. For the sake of economy, throughout the remainder of this book, we’ll refer to Node.js simply as Node. Before writing your first line of code, it’s important to choose a text editor that sup‐ ports modern JavaScript development and integrates well with Node tooling. Installing VS Code Visual Studio Code (VS Code) is a popular open source text editor, widely recom‐ mended for Node development due to its robust features, flexibility, and extensive 1
📄 Page 16
customization options. This section will guide you through installing VS Code on macOS, Windows, and Linux. AI-powered code editors are becoming increasingly popular, and one such tool is Cursor, an AI-enhanced editor built on VS Code that can assist with code suggestions and explanations. While help‐ ful, beginners should balance its use with learning core concepts independently. The easiest way to install VS Code is by visiting the VS Code download page. Figure 1-1 displays the installation options for each operating system. Figure 1-1. VS Code installation page The image provides options for installing VS Code on Mac, Windows, and Linux sys‐ tems. The following sections break down how to proceed on each operating system. Mac Installation Make sure to identify the type of Mac you have (Intel or Apple Silicon). 1. Download the appropriate installer for your Mac. 2. Open the downloaded file and drag the VS Code icon to the Applications folder. 2 | Chapter 1: Introduction and Setup
📄 Page 17
3. Open VS Code from the Applications folder. You may need to allow the application to run in System Preferences under Security & Privacy if you encounter any issues. Windows Installation To install VS Code on a Windows machine, follow these steps: 1. Download the installer for Windows. 2. Open the downloaded file and follow the installation wizard steps. 3. Once installed, you can launch VS Code from the Start Menu. During installation, ensure you select the option to add VS Code to your PATH for easy command-line access. Linux Installation The installation for Linux machines is a bit different, as it requires command-line steps. For the standard Debian/Ubuntu machine setup, run the following commands in your command-line window: sudo apt update sudo apt install software-properties-common apt-transport-https wget wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | \ sudo apt-key add - sudo add-apt-repository \ "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" sudo apt update sudo apt install code Updates the package lists to ensure you get the latest version and dependencies. Installs required tools for adding repositories and handling HTTPS. Downloads and adds the Microsoft GPG key to verify packages. Adds the official Microsoft VS Code repository. Installing VS Code | 3
📄 Page 18
Updates the package lists again to include the new VS Code repository. Installs VS Code. For other distributions, refer to the official documentation. To improve your development experience, consider installing VS Code extensions such as Prettier for formatting, ESLint for catching bugs early, and npm Intellisense for smart autocomplete when importing packages. With your editor ready to go, let’s take a moment to understand what Node is and why it’s the core technology behind everything you’ll build in this book. Understanding Node Node is an open source tool, which means anyone can view, modify, and share its code for free. It’s also cross-platform, so it works on different operating systems like Windows, macOS, and Linux. Node is a runtime, meaning it provides an environ‐ ment for running JavaScript code outside the browser—normally, JavaScript is only used inside web browsers for things like interactive buttons or animations. With Node, developers can use JavaScript to build server-side applications, like websites or APIs. Node is built on Chrome’s V8 JavaScript engine, a technology that converts JavaScript into machine code, which is the language your computer understands. This process makes JavaScript run faster and more efficiently. Because of this speed, Node is described as lightweight (it doesn’t require a lot of resources) and efficient (it gets a lot done with minimal overhead). It’s particularly great for creating scalable applica‐ tions, which means programs that can handle more users or data without slowing down. One of Node’s standout features is its nonblocking, event-driven architecture. In sim‐ ple terms, it doesn’t wait for one task to finish before starting another. Imagine you’re folding laundry and boiling water at the same time. Instead of waiting by the stove, you fold clothes until the water boils. Similarly, Node switches between tasks, maxi‐ mizing productivity. This is why Node is ideal for real-time applications like chat apps, online games, or tools where users collaborate live: everything stays responsive, even with many users. 4 | Chapter 1: Introduction and Setup
📄 Page 19
Why Node Stands Out Node has become a popular choice for developers due to its unique features and advantages: Unified development Uses JavaScript on both the client and server sides, eliminating the need for mul‐ tiple programming languages across your stack and simplifying development workflows. Vast ecosystem Includes npm, a massive package repository with millions of prebuilt tools, mak‐ ing it faster and easier to build applications. Industry adoption Trusted by leading companies like Netflix, LinkedIn, and PayPal for its ability to handle high traffic and real-time demands. Scalability and efficiency Designed to handle thousands of simultaneous connections without slowing down, thanks to its event-driven, nonblocking architecture. Smooth operations Node ensures requests flow efficiently, even under heavy workloads. Imagine a highway with no traffic jams. What’s Happening Under the Hood? Underneath, Node uses the V8 engine, which makes JavaScript fast by converting it directly into machine code. The magic of handling thousands of simultaneous tasks comes from Node’s event loop and Libuv library. The event loop is like a receptionist managing multiple customers at once: while one waits for a response (e.g., fetching data), the receptionist moves on to help others. Libuv is like the behind-the-scenes team that takes care of time-consuming tasks, such as reading files from a disk or resolving domain names (DNS lookups). While Node focuses on quickly switching between tasks, Libuv ensures that these slower operations happen in the background without blocking the main thread. Think of it like a chef in a busy kitchen—while the head chef keeps preparing quick dishes, Libuv is the team working on slow-cooking the stew. This allows Node to keep moving to the next task without getting stuck waiting for one operation to finish. Installing Node You’re about to install Node, a powerful and versatile platform that allows you to run JavaScript code on your computer, outside of a web browser. With Node, you can Installing Node | 5
📄 Page 20
build everything from simple websites to complex server-side applications, automate tasks, and much more. As you get started, keep in mind that installing Node is a straightforward process, but there are a few things to watch out for. Depending on your operating system, you might need to adjust some settings or install additional tools, like version managers or build essentials. Follow each step below, including tips for troubleshooting com‐ mon issues. For all installations, visit the Node download page, where you’ll be able to choose the Node installation for your machine setup (Figure 1-2). nvm (Node Version Manager) lets you easily install and switch between multiple versions of Node, which is ideal for testing projects across environments. Learn more by visiting the project’s GitHub repo. Figure 1-2. Node installation page 6 | Chapter 1: Introduction and Setup
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List