node.js in action
node.js 实战 高清pdf manning出版社For online information and ordering of this and other manning books, please visitwww.manning.com.ThepublisheroffersdiscountsonthisbookwhenorderedinquantityFor more information, please contactSpecial sales DepartmentManning publications co20 Baldwin roadPO Box 261Shelter island, NY11964Email:orders@manning.com@2014 by Manning Publications Co. All rights reservedNo part of this publication may be reproduced, stored in a retrieval system, or transmitted, inany form or by means electronic, mechanical, photocopying, or otherwise, without prior writtenpermission of the publisherMany of the designations used by manufacturers and sellers to distinguish their products areclaimed as trademarks. Where those designations appear in the book, and manningPublications was aware of a trademark claim, the designations have been printed in initial capsor all caps@o Recognizing the importance of preserving what has been written, it is Mannings policy to havethe books we publish printed on acid-free paper and we exert our best efforts to that endRecognizing also our responsibility to conserve the resources of our planet, Manning bookare printed on paper that is at least 15 percent recycled and processed without the use ofelemental chlorineManning publications coDevelopment editor: Renae gregoire20 Baldwin roadCopyeditor Andy carrollPO BOX 261Proofreader: Katie Tennanthelter island. ny11964Typesetter: Dottie marsicoCover designer: Marija TudorISBN9781617290572Printed in the united states of america12345678910-MAL-181716151413www.it-ebooksinfobrief contentsPART 1 NODE FUNDAMENTALS1■ Welcome to Node js3Building a multiroom chat application 148 Node programming fundamentals 37PART 2 WEB APPLICATION DEVELOPMENT WITH NODE694 Building node web applications 715 Storing Node application data 976■ Connect1237 Connect's built-in middleware 1458■ Express1769 Advanced Express 20210 Testing Node applications 24211 Web application templating 264PART 3 GOING FURTHER WITH NODE2932 Deploying Node applications and maintaining uptime 295Beyond web servers 30914 The node ecosystem 343iwww.it-ebooksinfowww.it-ebooksinfocontentsforeword xiiipreface xuacknowledgments xviabout this book xviiiabout the cover illustration xxPART 1 NODE FUNDAMENTALS............1Welcome to Node js 31.I Built on JavaScript 41.2 Asynchronous and evented: the browser 51.3 Asynchronous and evented the server 74 DIRTy applications 81.5 DIRTy by default 10SimpleasyncexampleliHelloworldhttpserver12Streaming data 121.6 Summary 1gBuilding a multiroom chat application 142.1Application overview 152.2 Application requirements and initial setup 17ServinghttpandWebsocket17Creatingtheapplicationfile structure 18 Specifying dependencies 19. Installingdependencies 19www.it-ebooksinfoCONTENTS2.8 Serving the applications HTML, CSS, and client-sideJavaScript 20Creating a basic static file server 20 Adding the htMl and cssfiles 232.4 Handling chat-related messaging using Socket IO 25Setting up the socket. 10 server 26 Handling applicationscenarios and events 272.5 USing client-side JavaScript for the application's userinterface 31Relaying messages and name/room changes to the server 32Showing messages and available rooms in the user interface 332.6 Summary 363Node programming fundamentals 378.1 Organizing and reusing Node functionality 38Creating modules 40. Fine-tuning module creation usingmodule exports 42 Reusing modules using the node modulesfolder 43 Caveats 443.2 Asynchronous programming techniques 46Handling one-off events with callbacks 46. Handling repeatingevents with event emitters 50. Challenges with asynchronousdevelopment 573.3 Sequencing asynchronous logic 58When to use serial flow control 59.Implementing serial flowcontrol 61. Implementing parallel flow control 63Leveraging community tools 653.4 Summary 67PART 2 WEB APPLICATION DEVELOPMENT WITH NODE.69Building Node web applications 714.1 Http server fundamentals 7How Node presents incoming Http requests to developers 73abasichttpserverthatrespondswith"helloworld74Reading request headers and setting response headers 75Settingthestatuscodeofanhttpresponse75www.it-ebooksinfoCONTENTS4.2 Building a RESTful web service 76Creating resources with Post requests 77 Fetching resourceswith get requests 79 Removing resources with DELETErequests 804. 3 Serving static files &1Creating a static file server 82- Handling server errors 85Preemptive error handling with fs. stat 864.4 Accepting user input from forms 87using formidable 90. Calcalating upload progress 9, ilesHandling submitted form fields 87 Handling uploaded files4.5 Securing your application with Https 944.6 Summary 96Storing Node application data 975.1 Serverless data storage 98In-memory storage 98 File-based storage gg5.2 Relational database management systems 102MySo102· PostgresQl105.3 NosoL databases 112Redis I12· MongODB117·Momg0ose1195.4 Summary 121Connect 1236.1 Setting up a Connect application 1246.2 How Connect middleware works 125Middleware that does logging 126. Middleware that respondsuitb“ hello world”1266. 8 Why middleware ordering matters 127When middleware doesnt call next( 128 Using middlewareorder to perform authentication 1286.4 Mounting middleware and servers 129Middleware that does authentication 130- A middlewarecomponent that presents an administration panel 131www.it-ebooksinfoCONTENTS6.5 Creating configurable middleware 133Creating a configurable logger middleware component 133Building a routing middleware component 135Building a middleware component to rewrite URLs 1376.6 USing error-handling middleware 138Connects default error handler 139- Handing application errorsyourself 139. Using multiple error-handling middlewarecomponents 1416. 7 Summary 144Connects built-in middleware 1457.1 Middleware for parsing cookies, request bodiesand query strings 146cookieparser(: parsing Http cookies 147 body Parserparsing request bodies 150 limit: request body limiting 151query(: query-string parser 1537.2 Middleware that implements core web applicationfunctions 154logger(: logging requests 155- favicon(: serving afavicon 157. methodoverride(: faking Http methods 158host(): virtual hosting 160 session(): sessionmanagement 1617. 8 Middleware that handles web application security 165basicauth( : Http Basic authentication 165 csrf(): cross-siterequest forgery protection 167 errorHandler(): development errorhandling1687.4 Middleware for serving static files 170static(: static file serving 170 compress(): compressing staticfiles 172 directory ( directory listings 1747.5 Summary 175Express 1768.1 Generating the application skeleton 178Installing the Express executable 180- Generating theapplication 180 Exploring the application 1808.2 Configuring Express and your application 188Environment-based configuration 183www.it-ebooksinfoCONTENTS8.3 Rendering views 185View system configuration 185 View lookup 188 Exposingdata to views 1898.4 Handling forms and file uploads 194Implementing the photo model 194. Creating a photo uploadform 194. Showing a list of uploaded photos 1978.5 Handling resource downloads 198Creating the photo download route 198. Implementing the photodownload route 998.6 Summary 201Advanced Express 2029.1 Authenticating users 203Saving and loading users 204. Registering new users 209Logging in registered users 214. User-loading middleware 2179.2 Advanced routing techniques 219Validating user content submission 219. route-specificmiddleware 223. Implementing pagination 2259.8 Creating a publiC REST API 229Designing the apI 229 Adding Basic authentication 229Implementing routing 230- Enabling content negotiation 2349. 4 Error handling 286Handling 404 errors 236 Handling errors 2389.5 Summary 241Testing Node applications 24210.1 Unit testing 248The assert module 244. Nodeunit 247- Mocha 249Vos254· Shoula.s25610.2 Acceptance testing 258Tobi259·Soda26010.3 Summary 262Web application templating 26411. 1 Using templating to keep code clean 265Templating in action 266www.it-ebooksinfo
下载地址
用户评论
只是第一版