Great Node.js: to the end of JavaScript (Web development preferred, real time, a

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Great Node.js: to the end of JavaScript (Web development preferred, real time, across multiple servers, high concurrency)

Guillermo Rauch For making

Translated by Zhao Jing

ISBN 978-7-121-21769-2

2014Published in January

Price: 79 yuan

320Page

16Open


 

The editor recommends

Node.js is a JavaScript written by a powerful web development framework, which makes the server web application development strong, good scalability becomes more simple, easy. This book shows you what is Node and how to let you use it in the project. The book contains a lot of practical application examples of procedures, show why Node.js will quickly become the reason web development tool of choice, through this book, you can quickly familiar with and master the required to achieve the following objectives of Node knowledge and skills:

Understanding the Node event polling based on architecture, non blocking IO and event driven programming mode

Proficient in Node.js API

Easy to achieve development technology relevant real-time applications, such as SOCKET.IO and HTML5 WEBSOCKETS

Preparation of highly concurrent applications can support across multiple servers

To support multiple databases and data storage tools by Node

Writing can handle million level concurrency in the single server case procedure

To be in a contained more Node knowledge and annotation examples (including source code) web site and other developers, real time communication

The book contains a lot of full-color illustrations and practical source code, is a practical guide to the revolutionary web development tool -- Node.

Abstract

This book is a classic Learning by Doing books. It consists of the Node community Socket.IO famous author -- Guillermo Rauch, through practice a lot of writing, and by the Node community is very active Developer -- Goddy Zhao translated.

The book consists of five parts: the introduction of Node core design philosophy, Node core module API, Web development, database and test. From the front to the back, from the outside to the inside of each link using Node for the development of Web are discussed in depth, and the biggest characteristic is through the actual case, code display a large number of analysis technology, on best practice.

Catalog

PART I started from the installation and concept

The CHAPTER 1 installation..... 3

Under Windows installed..... 3

Installed in the OS.X.... 4

Under Linux installed... 5.

The compiler.... 5

Ensure that the installation was successful......5

Node.REPL................................................. 5

Executable file... 6.

NPM................................................................. 6

Install the module.....7

Custom modules.....8

Install binary toolkit......9

Browse the NPM warehouse.....9

Summary..... 10

CHAPTER 2 JavaScript Overview.....11

The... 11.

JavaScript based..... 12

Type.... 12

Types of confusion...... 12

Function.... 13.

THIS, FUNCTION #CALL and FUNCTION#APPLY.................... 14

The function of the number of parameters.... 14

Closure...... 14

Class...... 15

Inheritance...... 16

TRY.{}.CATCH.{}...................................... 17

V8 JavaScript... 17.

OBJECT#KEYS....................................................... 18

ARRAY#ISARRAY................................................ 18

Array method... 18.

The string method.... 19.

JSON............................................................. 19

FUNCTION#BIND....................................................... 19

 FUNCTION#NAME.............................................. 19

_PROTO_ (inheritance)...... 20

Accessor... 20.

Summary..... 21

CHAPTER 3 blocking and non blocking IO... 23

The ability is stronger, the greater the responsibility... 23.

Obstruction.... 25.

A single thread in the world...... 27

Error handling..... 29

A stack trace... 30

Summary... 32

CHAPTER 4 Node JavaScript... 33.

The global object... 33.

The utility of the global object.... 34

Modular system... 34

The absolute and relative module...... 35

Exposure to API.... 37

The event... 38

 buffer............................................................... 40

Summary... 41.

PART Ⅱ Node important API

CHAPTER 5 command line tool (CLI) and FS API: the first Node application... 45.

The demand... 45.

Write the first Node program..... 46

Creating module... 46.

Synchronous or asynchronous.... 47.

To understand what is the flow of(stream)................................... 49

The input and output.... 50.

Reconstruction.... 53.

File operations with FS.... 55

The CLI for a closer look.... 56.

argv.................................................... 57

The working directory..... 57

Environment variables... 58.

Exit...... 58

Signal.... 58.

ANSI escape code..... 59

The FS for a closer look.... 59.

Stream......................................................... 59

Monitoring.... 60

Summary... 61

CHAPTER 6 TCP ........................................... 63

What are the characteristics of TCP...... 64

Connection oriented communication and ensure the delivery order.... 64

Byte oriented... 65.

Reliability..... 65

Flow control..... 65

Congestion control... 65.

Telnet................................................................ 65

TCP based chat program..... 68

Creating module... 68.

Understanding the NET.SERVER.API... 68

Receiving a connection... 70

The data event.... 71

State and recording connection.... 73.

The successful completion of this program...... 75

An IRC client program... 77

Creating module... 77.

Understanding of NET#STREAM.API.. ......................................... 78

Part of the IRC protocol...... 78

Testing the actual IRC server.... 78.

Summary..... 79

CHAPTER 7 HTTP .................................................. 81

The structure of HTTP... 81

The header information.... 82

Connection..... 87

A simple Web server..... 88

Creating module... 88

The output form... 88.

Method and URL.... 90.

Data.... 92.

Integration.... 94

Make the program more robust.... 95.

A Twitter.Web client..... 96

Creating module... 96

Send a simple HTTP requests.... 97.

To send data..... 98

Gets the tweets... 99.

SuperAgent to save... 102.

The use of up to restart the HTTP server... 103.

Summary... 104

PART Ⅲ Web development

CHAPTER 8 Connect .............................. 107

Building a simple website using HTTP.... 108

Through the Connect to achieve a simple website..... 111

Middleware.... 112.

Write reusable middleware.....114

Static middleware.... 119

Query Middleware.... 120

Logger middleware... 120

Body.parser middleware.... 122

cookie.........................................................125

Conversation(session). ......................................126

Redis.session..................................................131

MethodOverride middleware.... 132

BasicAuth middleware......132

Summary..... 134

CHAPTER 9 Express..................................................135

A small Express application...... 135

Creating module....136

 HTML...........................................................136

 SETUP..........................................................137

Defines the routing.....137

The query.....140

Operation......141

Set... 142

Template engine... 143

Error handling..... 144

Fast method... 144.

Routing... 146

Middleware.... 148.

Code organization strategy...... 149

Summary... 151.

CHAPTER 10 WebSocket .................. 153

Ajax.............................................. 153

HTML5.WebSocket............................................... 156

An example of a ECHO.... 157

The initialization program.... 157

The establishment of server......158

The establishment of the client......159

Running the sample program......160

The mouse cursor... 161

Initialize the sample program......161

The establishment of server......161

The establishment of the client.....164

Running the sample program......166

Face a challenge.... 166

Shut down does not mean that the disconnected......166

JSON...........................................167

Reconnection.... 167

The broadcast.... 167

WebSocket belongs to the HTML5: early browser does not support......167

The solution....167

Summary... 167.

CHAPTER 11 Socket.IO.............................................169

Transmission... 170.

Disconnect the.VS. closed......170

Event.... 170

Namespace....171

Chat program... 172.

The initialization procedure.... 172

The construction of server.... 172

Construction of the client.... 173

The event and broadcast.....175

Message acknowledgement.... 179

A take turns to do the DJ application..... 180

Extended chat application.....181

Integrated Grooveshark.API.....182

Play the songs.....185

Summary... 190.

PART IV database

CHAPTER 12 MongoDB.......................193

Install..... 195

The use of MongoDB: a user authentication example.... 195.

Build the application.... 195

Create a Express.App..... 196

Connect the MongoDB......200

Create a document.....201

Find document....203

Authentication middleware.....204

Check......205

Atomic....206

Safe mode.....206

Mongoose introduces..... 206

Define the model....207

Defines a nested keys......208

Defines a nested document.....209

The index construction... 209

Middleware....209

Detection model of the state.....210

The query.....210

Query expansion....210

Sorting.....211

Choice.... 211

Be....211

Skip......211

Automatically generated key.....211

Conversion.....212

An example of the use of Mongoose... 212.

Construction of the application... 212

Reconstruction.... 213

To establish the model of... 213

Summary... 215

CHAPTER 13 MySQL...........................................217

node-mysql........................................ 217

The initialization program.... 217

Application of Express......218

Connect the MySQL.....219

Initialization script.... 220

Create a data... 224

To obtain the data....228

sequelize............................................ 229

Initialize the sequelize......230

Initialize the Express application.... 230

Connect the sequelize.....233

Define the model and synchronization.... 234

Create a data... 236

To obtain the data.....238

Delete data... 239

Application of complete integrity.....240

Summary... 241

CHAPTER 14 Redis......................................... 243

Install the Redis..... 244

The Redis query language...... 245

Data type... 245

String......246

Hash.....246

List...... 248

Data set.....249

Ordered data set......249

Redis and Node.... 249

Using node-redis to achieve a social graph.....250

Summary..... 259

PART V test

CHAPTER 15 code sharing... 263

What kind of code can be shared... 263.

Writing compatible JavaScript code..... 264

Export module... 264

ECMA.API. simulation of the realization of.....265

Node.API. simulation of the realization of.....267

Simulation of the browser API.....267

Inheritance of cross browser implementation.... 268

Integrated together: browserbuild. ...................... 268

The base case... 269

Summary..... 271

CHAPTER 16 test..... 273

A simple test... 273.

The test target... 274

The test strategy..... 274

The test program... 275

expect.js................................................. 276

API list......276

Mocha................................................. 278

Test asynchronous code.....279

BDD style......281

TDD style.... 281

Export style.... 282

In the browser using Mocha......282

Summary... 284

The index..... 285

Author brief introduction

Guillermo Rauch (San Francisco, California) is a company located in San Francisco, as

To provide related services to local education LearnBoost CTO and co-founder of Venture Company.

Rauch or Node.js project, several well-known inventor, once in JSConf and some

Node.js workshop lecture. "

The translator's introduction:

Goddy Zhao (Zhao Jing), Successfactors (SAP company) software engineer. Graduated from the Fudan University, in IBM, Taobao work, focus in the development of enterprise Web application, good at combining technology solutions before and after the end of. Who co translated books in front of books, and served in the Shanghai JS and D2 front-end technology forum served as host and guest lectures. Personal home page http: //goddyzhao.me.

Media comment

The book is excellent -- Amazon.com reader Shawn Rapp

This book at the points, and no useless crap, is every phrase a gem -- Amazon.com reader Pragmateek

The book of accurate positioning, with a simple but robust model to help beginners on using Node.js to create more complex application way. This be concise and to the point of writing liked, for teaching is very successful, is one of the effective use of Node.js reference book. Readers -- Amazon.com Pmjtoca

Preface

Most Web applications includes client and server in two parts. The server is often complicated, troublesome. Create a simple server requirements of multi thread, scalability and server deployment have professional and technical knowledge. In addition, because the client software is realized by HTML and JavaScript, and the server core code is usually achieved using static programming language, therefore, the development of Web application are often confused feelings. Because of this difference before and after the end of the development of language, to allow developers to use a variety of programming languages, but also on the program logic specific prior to the design selection.

A few years ago, to use JavaScript to implement the server software is almost a thing want to all dare not to think. Memory management bad performance, immature and lack of integrated operating system level, do not solve these problems, JavaScript is difficult to become a server-side language. As part of the Google Chrome browser, the new V8 engine can solve the first two problems. V8 is an open source project, through a simple API can integrate it into the.

Ryan Dahl insight into such an opportunity, through the integration layer V8 is embedded in the operating system, to make JavaScript enjoy the asynchronous interface to the underlying operating system, so as to realize its belt to the server end. This is the Node.js design. The benefits of doing so is obviously. Programmers can use the same programming language on the client and server. Characteristics of dynamic language JavaScript enables the development and testing of server-side code becomes free, allows programmers to get rid of the traditional kind of slow and heavy programming mode.

Node.js soon became popular, spawned a powerful open-source community, support enterprises, and even have their own technical conference. I call this success is due to its simplicity, efficiency, and improve the programming productivity. I'm glad V8 became a small part of it.

This book will take readers learn how to build a server based on Node.js Web application, also will bring everyone to learn how to organize the asynchronous server code and how to interact with the database.

Enjoy this book brings the fun.!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Isidore at December 10, 2013 - 9:32 AM