文件名称:[Mastering.Node.js(2013.11) 精通Node.js
文件大小:3.02MB
文件格式:PDF
更新时间:2017-08-13 10:24:53
Node.js
学习node.js的好书 下面是目录: Preface 1 Chapter 1: Understanding the Node Environment 7 Extending JavaScript 9 Events 10 Modularity 12 The Network 13 V8 15 Memory and other limits 16 Harmony 18 The process object 19 The Read-Eval-Print Loop and executing a Node program 21 Summary 23 Chapter 2: Understanding Asynchronous Event-Driven Programming 25 Broadcasting events 26 Collaboration 28 Queueing 29 Listening for events 30 Signals 30 Forks 32 File events 34 Deferred execution 35 process.nextTick 36 Timers 38 setTimeout 38 setInterval 39 unref and ref 40Table of Contents [ ii ] Understanding the event loop 41 Four sources of truth 42 Callbacks and errors 44 Conventions 45 Know your errors 45 Building pyramids 47 Considerations 48 Listening for file changes 49 Summary 53 Chapter 3: Streaming Data Across Nodes and Clients 55 Exploring streams 57 Implementing readable streams 59 Pushing and pulling 61 Writable streams 62 Duplex streams 65 Transforming streams 65 Using PassThrough streams 66 Creating an HTTP server 67 Making HTTP requests 69 Proxying and tunneling 70 HTTPS, TLS(SSL), and securing your server 72 Creating a self-signed certificate for development 72 Installing a real SSL certificate 73 The request object 73 The URL module 74 The Querystring module 76 Working with headers 77 Using cookies 78 Understanding content types 80 Handling favicon requests 81 Handling POST data 82 Creating and streaming images with Node 83 Creating, caching, and sending a PNG representation 84 Summary 87 Chapter 4: Using Node to Access the Filesystem 89 Directories, and iterating over files and folders 90 Types of files 91 File paths 92 File attributes 94Table of Contents [ iii ] Opening and closing files 95 fs.open(path, flags, [mode], callback) 96 fs.close(fd, callback) 97 File operations 97 fs.rename(oldName, newName, callback) 97 fs.truncate(path, len, callback) 97 fs.ftruncate(fd, len, callback) 97 fs.chown(path, uid, gid, callback) 98 fs.fchown(fd, uid, gid, callback) 98 fs.lchown(path, uid, gid, callback) 98 fs.chmod(path, mode, callback) 98 fs.fchmod(fd, mode, callback) 98 fs.lchmod(path, mode, callback) 99 fs.link(srcPath, dstPath, callback) 99 fs.symlink(srcPath, dstPath, [type], callback) 99 fs.readlink(path, callback) 100 fs.realpath(path, [cache], callback) 100 fs.unlink(path, callback) 101 fs.rmdir(path, callback) 101 fs.mkdir(path, [mode], callback) 101 fs.exists(path, callback) 101 fs.fsync(fd, callback) 101 Synchronicity 102 Moving through directories 103 Reading from a file 105 Reading byte by byte 106 fs.read(fd, buffer, offset, length, position, callback) 106 Fetching an entire file at once 107 fs.readFile(path, [options], callback) 107 Creating a readable stream 107 fs.createReadStream(path, [options]) 108 Reading a file line by line 108 The Readline module 109 Writing to a file 110 Writing byte by byte 110 fs.write(fd, buffer, offset, length, position, callback) 110 Writing large chunks of data 112 fs.writeFile(path, data, [options], callback) 112 fs.appendFile(path, data, [options], callback) 112 Creating a writable stream 113 fs.createWriteStream(path, [options]) 113 Caveats 113 Serving static files 114 Redirecting requests 114 Location 115 Implementing resource caching 116Table of Contents [ iv ] Handling file uploads 118 Putting it all together 120 Summary 121 Chapter 5: Managing Many Simultaneous Client Connections 123 Understanding concurrency 126 Concurrency is not parallelism 126 Routing requests 127 Understanding routes 129 Using Express to route requests 131 Using Redis for tracking client state 132 Storing user data 134 Handling sessions 135 Cookies and client state 135 A simple poll 136 Centralizing states 138 Authenticating connections 140 Basic authentication 141 Handshaking 143 Summary 146 Further reading 146 Chapter 6: Creating Real-time Applications 147 Introducing AJAX 149 Responding to calls 151 Creating a stock ticker 152 Bidirectional communication with Socket.IO 156 Using the WebSocket API 157 Socket.IO 159 Drawing collaboratively 161 Listening for Server Sent Events 165 Using the EventSource API 166 The EventSource stream protocol 169 Asking questions and getting answers 171 Building a collaborative document editing application 178 Summary 182 Chapter 7: Utilizing Multiple Processes 183 Node's single-threaded model 185 The benefits of single-threaded programming 186 Multithreading is already native and transparent 189 Creating child processes 190Table of Contents [ v ] Spawning processes 192 Forking processes 195 Buffering process output 197 Communicating with your child 198 Sending messages to children 199 Parsing a file using multiple processes 200 Using the cluster module 203 Cluster events 205 Worker object properties 205 Worker events 206 Real-time activity updates of multiple worker results 206 Summary 212 Chapter 8: Scaling Your Application 213 When to scale? 214 Network latency 215 Hot CPUs 216 Socket usage 218 Many file descriptors 218 Data creep 218 Tools for monitoring servers 220 Running multiple Node servers 220 Forward and reverse proxies 220 Nginx as a proxy 222 Using HTTP Proxy 225 Message queues – RabbitMQ 227 Types of exchanges 228 Using Node's UDP module 230 UDP multicasting with Node 233 Using Amazon Web Services in your application 236 Authenticating 237 Errors 238 Using S3 to store files 239 Working with buckets 239 Working with objects 240 Using AWS with a Node server 243 Getting and setting data with DynamoDB 244 Searching the database 247 Sending mail via SES 248 Authenticating with Facebook Connect 250 Summary 253Table of Contents [ vi ] Chapter 9: Testing Your Application 255 Why testing is important 256 Unit tests 257 Functional tests 257 Integration tests 258 Native Node testing and debugging tools 259 Writing to the console 259 Formatting console output 261 The Node debugger 263 The assert module 267 Sandboxing 270 Distinguishing between local scope and execution context 271 Using compiled contexts 272 Errors and exceptions 272 The domain module 275 Headless website testing with ZombieJS and Mocha 277 Mocha 278 Headless web testing 279 Using Grunt, Mocha, and PhantomJS to test and deploy projects 281 Working with Grunt 283 Summary 284 Appendix A: Organizing Your Work 285 Loading and using modules 286 Understanding the module object 287 Resolving module paths 288 Using npm 290 Initializing a package file 290 Using scripts 291 Declaring dependencies 292 Publishing packages 293 Globally installing packages and binaries 294 Sharing repositories 295 Appendix B: Introducing the Path Framework 297 Managing state 299 Bridging the client/server divide 300 Sending and receiving 302 Achieving a modular architecture 303 Appendix C: Creating Your Own C++ Add-ons 307 Hello World 309 Creating a calculator 311Table of Contents [ vii ] Implementing callbacks 313 Closing thoughts 314 Links and resources 315 Index 317