万本电子书0元读

万本电子书0元读

顶部广告

Mastering Node.js - Second Edition电子书

售       价:¥

4人正在读 | 0人评论 9.8

作       者:Sandro Pasquali,Kevin Faaborg

出  版  社:Packt Publishing

出版时间:2017-12-29

字       数:67.2万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Expert techniques for building fast servers and scalable, real-time network applications with minimal effort; rewritten for Node.js 8 and Node.js 9 About This Book ? Packed with practical examples and explanations, Mastering Node.js contains everything you need to take your applications to the next level. ? Unleash the full potential of Node.js 9 to build real-time and scalable applications. ? Gain in-depth knowledge of asynchronous programming, event loops, and parallel data processing. ? Explore Node's innovative event-non-blocking design, and build professional applications with the help of detailed examples. Who This Book Is For This book is targeted at JavaScript developers who want to take an in-depth look at the latest Node.js framework to create faster, scalable, real-time backend applications. Basic JavaScript programming knowledge—and also some previous Node.js development experience—are mandatory to get the best out of this book What You Will Learn ? Build an Electron desktop app using Node that manages a filesystem ? Explore Streams and understand how they apply to building networked services ? Develop and deploy an SMS-driven customer service application ? Use WebSockets for rapid bi-directional communication ? Construct serverless applications with Amazon Lambda ? Test and debug with headless browsers, CPU profiling, Mocha, Sinon, and more ? Scale applications vertically and horizontally across multiple cores and web services In Detail Node.js, a modern development environment that enables developers to write server- and client-side code with JavaScript, thus becoming a popular choice among developers. This book covers the features of Node that are especially helpful to developers creating highly concurrent real-time applications. It takes you on a tour of Node's innovative event non-blocking design, showing you how to build professional applications. This edition has been updated to cover the latest features of Node 9 and ES6. All code examples and demo applications have been completely rewritten using the latest techniques, introducing Promises, functional programming, async/await, and other cutting-edge patterns for writing JavaScript code. Learn how to use microservices to simplify the design and composition of distributed systems. From building serverless cloud functions to native C++ plugins, from chatbots to massively scalable SMS-driven applications, you'll be prepared for building the next generation of distributed software. By the end of this book, you'll be building better Node applications more quickly, with less code and more power, and know how to run them at scale in production environments. Style and approach Mastering Node.js contains all of the examples and explanations you'll need to build applications in a short amount of time and at a low cost, running rapidly and at scale.
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部