售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Second Edition
Copyright
Mastering Node.js
Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Understanding the Node Environment
Introduction – JavaScript as a systems language
The Unix design philosophy
POSIX
Events for everything
Standard libraries
Extending JavaScript
Events
Modularity
The network
V8, JavaScript, and optimizations
Flags
Optimizing your code
Numbers and tracing optimization/de-optimization
Objects and arrays
Functions
Optimized JavaScript
Help with variables
Arrow functions
String manipulation
The process object
The REPL
Summary
Understanding Asynchronous Event-Driven Programming
Node's unique design
Collaboration
Queueing
Understanding the event loop
Event loop ordering, phases, and priorities
Listening for events
Signals
Child processes
File events
Deferred execution
process.nextTick
setImmediate
Timers
setTimeout
setInterval
unref and ref
Concurrency and errors
Managing concurrency
Callbacks
Promises
async/await
Generators and Iterators
Errors and exceptions
Considerations
Building a Twitter feed using file events
Summary
Streaming Data Across Nodes and Clients
Why use streams?
Exploring streams
Implementing readable streams
Pushing and pulling
Writable streams
Duplex streams
Transforming streams
Using PassThrough streams
Creating an HTTP server
Making HTTP requests
Proxying and tunneling
HTTPS, TLS (SSL), and securing your server
Creating a self-signed certificate for development
Installing a real SSL certificate
The request object
The URL module
The Querystring module
Working with headers
Using cookies
Understanding content types
Handling favicon requests
Handling POST data
Creating and streaming images with Node
Creating, caching, and sending a PNG representation
Summary
Using Node to Access the Filesystem
Directories, and iterating over files and folders
Types of files
File paths
File attributes
Opening and closing files
fs.open(path, flags, [mode], callback)
fs.close(fd, callback)
File operations
fs.rename(oldName, newName, callback)
fs.truncate(path, len, callback)
fs.ftruncate(fd, len, callback)
fs.chown(path, uid, gid, callback)
fs.fchown(fd, uid, gid, callback)
fs.lchown(path, uid, gid, callback)
fs.chmod(path, mode, callback)
fs.fchmod(fd, mode, callback) ----
fs.lchmod(path, mode, callback)
fs.link(srcPath, dstPath, callback)
fs.symlink(srcPath, dstPath, [type], callback)
fs.readlink(path, callback)
fs.realpath(path, [cache], callback)
fs.unlink(path, callback)
fs.rmdir(path, callback)
fs.mkdir(path, [mode], callback)
fs.exists(path, callback)
fs.fsync(fd, callback)
Synchronicity
Moving through directories
Reading from a file
Reading byte by byte
fs.read(fd, buffer, offset, length, position, callback)
Fetching an entire file at once
fs.readFile(path, [options], callback)
Creating a readable stream
fs.createReadStream(path, [options])
Reading a file line by line
The Readline module
Writing to a file
Writing byte by byte
fs.write(fd, buffer, offset, length, position, callback)
Writing large chunks of data
fs.writeFile(path, data, [options], callback)
fs.appendFile(path, data, [options], callback)
Creating a writable stream
fs.createWriteStream(path, [options])
Caveats
Serving static files
Redirecting requests
Location
Content-Location
Implementing resource caching
Handling file uploads
Putting it all together
A simple file browser
Electron
Electron processes
The renderer process
Vue.js
Summary
Managing Many Simultaneous Client Connections
Understanding concurrency
Concurrency is not parallelism
Routing requests
Understanding routes
Using Express to route requests
Using Redis for tracking client state
Storing user data
Handling sessions
Cookies and client state
A simple poll
Authenticating connections
Basic authentication
Handshaking
Using JSON Web Tokens for authentication
Summary
Further reading
Creating Real-Time Applications
Introducing AJAX
Responding to calls
Creating a stock ticker
Bidirectional communication with socket.io
Using the WebSocket API
socket.io
Drawing collaboratively
Listening for Server Sent Events
Using the EventSource API
The EventSource stream protocol
Asking questions and getting answers
Building a collaborative document editing application
Summary
Using Multiple Processes
Node's single-threaded model
The benefits of single-threaded programming
Multithreading is already native and transparent
Creating child processes
Spawning processes
Forking processes
Buffering process output
Communicating with your child
Sending messages to children
Parsing a file using multiple processes
Using the cluster module
Cluster events
Worker object properties
Worker events
Using PM2 to manage multiple processes
Monitoring
Process files
Real-time activity updates of multiple worker results
Summary
Scaling Your Application
When to scale?
Network latency
Hot CPUs
Socket usage
Many file descriptors
Data creep
Tools for monitoring servers
Running multiple Node servers
Forward and reverse proxies
Using the http-proxy module
Deploying a NGINX load balancer on Digital Ocean
Installing and configuring NGINX
Message queues – RabbitMQ
Types of exchanges
Using Node's UDP module
UDP multicasting with Node
Using Amazon Web Services in your application
Authenticating
Errors
Using S3 to store files
Working with buckets
Working with objects
Using AWS with a Node server
Getting and setting data with DynamoDB
Searching the database
Sending mail via SES
Using Twilio to create an SMS bot on Heroku
Using Twilio webhooks to receive and send SMS messages
The switchboard
The ThankYou interface
Summary
Microservices
Why microservices?
From 3-Tiers to 4-Tiers
Monoliths
From monoliths to 3-Tiered architectures
How did this architecture come about?
Service-Oriented Architectures
4-Tiers and microservices
Deploying microservices
Microservices with Seneca
Serverless applications
AWS Lambda
Scaling with Claudia and API Gateway
Installing claudia and deploying a service
Containerized microservices
Getting started with Docker
Creating a Dockerfile
Running containers
Orchestrating Containers with Kubernetes
Creating a basic Kubernetes cluster
Declaring Pod deployments
Summary
Testing Your Application
Why testing is important
Unit tests
Functional tests
Integration tests
Native Node testing and debugging tools
Writing to the console
Formatting console output
The util.format(format, [arg, arg…]) method
The util.inspect(object, [options]) method
The Node debugger
The assert module
Sandboxing
Distinguishing between local scope and execution context
Using compiled contexts
Testing with Mocha, Chai, and Sinon
Mocha
Chai
Sinon
Spies
Stubs
Mocks
Headless testing with Nightmare and Puppeteer
Nightmare
Puppeteer
Testing the terrain
Testing processes, memory, and CPU
Profiling processes
Dumping the heap
Connecting Node to Chrome DevTools
CPU profiling
Live debugging
Summary
Organizing Your Work into Modules
How to load and use modules
The module object
Modules, exports, and module.exports
Modules and caching
How Node handles module paths
Creating a package file
Easy init
Adding scripts to package.json
npm as a build system using custom scripts
Registering package dependencies
Publishing and managing NPM packages
Global installs and binaries
Other repositories
Lockfiles
Creating Your Own C++ Add-ons
Hello World
A calculator
Using NAN
Hello, nan
Asynchronous add-ons
Closing thoughts
Links and resources
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜