Introduction
- Welcome to Node.js and Express.js!
- What You’ll Learn
- How You’ll Learn
- What You Should Already Know
- The Tools You’ll Need
- A Personal Note
- Let’s Begin!
Getting Started with Node.js
- Install Node.js on Your System
- Create a New Directory for Your Project
- Create a package.json File
- Why Node.js
- Node’s Module Support
- Create HTTP Servers with Node.js
- The
http.ServerResponseAPIs - How to Run JavaScript Code on the Command Line
- What Can You Build with Node.js?
File Management in Node.js
- Types of Interfaces in the File System Module
- Add the Callback-Based File System Module to Your Node.js App
- Add the Promise-Based File System Module to Your Node.js App
- Important File System Module Methods for Managing Files in Node.js
- The node:fs Module Gives You APIs to Work with a Computer’s File System
File Uploads in Node.js
- Create a New Project Directory
- Create a
package.jsonFile - Create a Form for Uploading Files
- Install the Formidable Package
- Use the Formidable Module in Your Node.js Application
- Run Your Application
- What Is the Formidable
parse()Method? - Specify Where Formidable Should Save the Uploaded Files
URL Management in Node.js
- How to Use the Node.js
urlModule - URL Constructor – Parse URLs
- fileURLToPath Function – Resolve File URLs to Paths
- pathToFileURL Function – Resolve Paths to URLs
- The
node:urlModule Provides APIs for Working with URLs
Serve Webpages in Node.js
- Create a New Project Directory
- Create the HTML Files for the Webpages You Wish to Serve
- Configure a Web Server to Respond to Browser Requests by Serving Webpages
- Run Your Application
Event Management in Node.js
- Add the Events Module to Your Node.js Application
- Create and Trigger Events with the
EventEmitterAPI - Important Emitter Methods for Managing Events in Node.js
- The
node:eventsModule Provides APIs for Event Management
Use Express.js to Simplify HTTP Request Handling in Node
- Create a Project Directory
- Create a package.json File
- Configure the Project as an ES Module Application
- Why Express.js?
- Raw Node.js Code vs. Express.js Code
- Important Stuff to Know About Creating Express.js Web Servers in Node.js
Routes, Middleware, and Controllers in Express.js
- Syntax of a Route in Express
- Middleware vs. Route Handler
- Examples
- Important Things to Know about the
nextParameter - Categories of Middleware in Express.js
Route vs. Query Parameters in Express.js
- Create a New Project Directory
- Create a package.json File
- Configure the Project as an ES Module Application
- Install Express
- Configure a Web Server to Respond to Browser Requests
- What Is a Query Parameter in Express?
- What Is a Route Parameter in Express?
Router in Express.js
- Create a New Project Directory
- Create a
package.jsonFile - Configure the Project as an ES Module Application
- Install Express
- Group Related Routes and Middleware
- Configure the Main Express Application
- Run Your Express.js Application
- Important Things to Know about Express Routers
Views in Express.js
- Create a New Project Directory
- Create a package.json File
- Configure the Project as an ES Module Application
- Install Express
- Types of Views in Express.js
- What Are Static Views in Express.js?
- What Are Dynamic Views in Express.js?
Handling Form Data in Express.js
- Validation vs Sanitization vs Output Escaping: What’s the Difference?
- Types of Form Validation
- What Is Client-Side Form Validation?
- What Is Server-Side Form Validation?
- How to Use Express-Validator to Validate a Form’s Data
- Important Things to Know About Validation, Sanitization, and Output Escaping in Express
- POST vs GET Method Attributes in HTML Forms
Connect a Frontend Application to a Node.js Backend
- Create a New Project Directory
- Create the Frontend and Backend Project Directories
- Configure the Project’s Backend
- Configure the Project’s Frontend
- Configure CORS in the Backend
- Run Your Full-Stack Application
- Send Data from the Frontend to the Express Backend
- Use
express.json()to Parse a JSON Request Body
Deploy a Full-Stack Application
- Deploy Your Backend Application to Render
- Deploy Your Frontend Application to Vercel
Manage User Sessions in Express with Express-Session
- Create a Basic Express Application
- Inspect Your App’s Cookies in the Browser
- Add Session Support with express-session
- Understand the Three Session-Related Properties
- Explore the Session Properties in Action
Test Express HTTP Endpoints with Supertest and node:test
- What’s the Difference Between a Test Runner and an HTTP Testing Tool?
- Create a Project Directory
- Create a
package.jsonFile - Configure the Project as an ES Module Application
- Install Express
- Install the HTTP Testing Library
- Test HTTP Requests
- Run the App Script
- Use the
node:testModule to Run Tests - Configure the App’s Web Server
- Run the Express.js Web Server
- Important Things to Know about Testing HTTP Endpoints
Use TypeScript with Express.js
- Create a Project Directory
- Create a package.json File
- Configure the Project as an ES Module Application
- Install Express
- Install TypeScript and Type Definitions
- Configure a Web Server to Respond to Browser Requests
- Run the Express Web Server
Add ESLint to an Express Application
- Initialize ESLint’s Configuration
- Lint Your Code
- Customize ESLint Rules
- Specify the Files ESLint Should Ignore
Epilogue
- What Next?
- Keep Growing
- One Last Favor
- Final Words