Home Page Icon
Home Page
Table of Contents for
Code Snippets
Close
Code Snippets
by Marc Wandschneider
Learning Node.js, Second Edition
About This E-Book
Title Page
Copyright Page
Dedication Page
Contents at a Glance
Contents
Acknowledgments
About the Author
Introduction
Why Node.js?
The Web
New Technologies
What Exactly Is Node.js?
Who Is This Book For?
How to Use this Book
Download the Source Code
Part I: Learning to Walk
1. Getting Started
Installing Node.js
Installation on Windows
Installation on the Mac
Installation on Linux
Running Node.js and “Hello World!”
The Node Shell
Editing and Running JavaScript Files
Your First Web Server
Debugging Your Node.js Programs
Staying Up-to-Date and Finding Help
Summary
2. A Closer Look at JavaScript
Types
Type Basics
Constants
Numbers
Booleans
Strings
Objects
Arrays
Type Comparisons and Conversions
Functions
Basics
Function Scope
Arrow Functions
Language Constructs
Classes, Prototypes, and Inheritance
Prototypes and Inheritance
Errors and Exceptions
Some Important Node.js Globals
global
console
process
Summary
3. Asynchronous Programming
The Old Way of Doing Things
The Node.js Way of Doing Things
Error Handling and Asynchronous Functions
The callback Function and Error Handling
Who Am I? Maintaining a Sense of Identity
Being Polite—Learning to Give Up Control
Synchronous Function Calls
Summary
Part II: Learning to Run
4. Writing Simple Applications
Your First JSON Server
Returning Some Data
Node Pattern: Asynchronous Loops
Learning to Juggle: Handling More Requests
More on the Request and Response Objects
Increased Flexibility: GET Params
Modifying Things: POST Data
Receiving JSON POST Data
Receiving Form POST Data
Summary
5. Modules
Writing Simple Modules
Modules and Objects
npm: The Node Package Manager
Consuming Modules
Searching for Modules
Module Caching
Cycles
Writing Modules
Creating Your Module
Developing with Your Module
Publishing Your Modules
Managing Asynchronous Code
The Problem
Our Preferred Solution—async
Making Promises and Keeping Them
Summary
6. Expanding Your Web Server
Serving Static Content with Streams
Reading a File
Serving Static Files in a Web Server with Buffers
Serving Up More Than Just HTML
Assembling Content on the Client: Templates
The HTML Skeleton Page
Serving Static Content
Modifying Your URL Scheme
The JavaScript Loader/Bootstrapper
Templating with Mustache
Your Home Page Mustache Template
Putting It All Together
Summary
Part III: Writing Web Applications
7. Building Web Applications with Express
Installing Express
Hello World in Express
Routing and Layers in Express
Routing Basics
Updating Your Photo Album App for Routing
REST API Design and Modules
API Design
Modules
Additional Middleware Functionality
Usage
Configurations
Ordering of Middleware
Static File Handling
POST Data, Cookies, and Sessions
Better Browser Support for PUT and DELETE
Compressing Output
Adding Authentication to our Application
Getting Started
Laying Down the Plumbing
Creating a Login Form
Logging the User In
Restricting Access to a Page
Flash Messages
Running the Sample
Error Handling
Summary
8. Databases I: NoSQL (MongoDB)
Setting Up MongoDB
Installing MongoDB
Using Mongo DB in Node.js
Structuring Your Data for MongoDB
It’s All JavaScript
Data Types
Understanding the Basic Operations
Connecting and Creating a Database
Creating Collections
Inserting Documents into Collections
Updating Document Values
Deleting Documents from Collections
Querying Collections
Seeing it all in Action
Updating Your Photo Albums App
Writing the Low-Level Operations
Modifying the API for the JSON Server
Updating Your Handlers
Adding Some New Pages to the Application
Recapping the App Structure
Summary
9. Databases II: SQL (MySQL)
Getting Ready
Installing MySQL
Adding the mysql Module from npm
Creating a Schema for the Database
Basic Database Operations
Connecting
Adding Queries
Updating the Photo Sharing Application
Authenticating via the Database
Updating the API to Support Users
Examining the Core User Data Operations
Updating the Express Application for Authentication
Implementing User Authentication
Creating the User Handler
Hooking up Passport and Routes
Creating the Login and Register Pages
Summary
Part IV: Getting the Most Out of Node.js
10. Deployment and Development I: Rolling Your Own
Deployment
Level: Basic
Level: Ninja
Multiprocessor Deployment: Using a Proxy
Multiple Servers and Sessions
Virtual Hosting
Express Support
Securing Your Projects with HTTPS/SSL
Generating Test Certificates
Built-in Support
Proxy Server Support
Multiplatform Development
Locations and Configuration Files
Handling Path Differences
Summary
11. Deployment and Development II: Heroku and Azure
Deploying to Heroku
Before We Begin
Preparing Your Deployment
Create and Deploy the Application on Heroku
We Have a Problem
And That’s It!
Deploying to Microsoft Azure
Before We Begin
Preparing Your Deployment
Create and Deploy the Application on Azure
We Have a Problem (and Déja Vu!)
And That’s It!
Summary
12. Command-Line Programming
Running Command-Line Scripts
UNIX and Mac
Windows
Scripts and Parameters
Working with Files Synchronously
Basic File APIs
Files and Stats
Listing Contents of Directories
Interacting with the User: stdin/stdout
Basic Buffered Input and Output
Unbuffered Input
The readline Module
Working with Processes
Simple Process Creation
Advanced Process Creation with Spawn
Summary
13. Testing
Choosing a Framework
Installing Nodeunit
Writing Tests
Simple Functional Tests
Groups of Tests
Testing Asynchronous Functionality
API Testing
Summary
Index
Code Snippets
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Learning Node.js
Next
Next Chapter
Images
Code Snippets
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset