PART Ⅰ 從安裝與概念開始
CHAPTER 1 安裝............................................... 3
在Windows下安裝............................................... 3
在OS.X下安裝. ................................................ 4
在Linux下安裝................................................. 5
編譯. ............................................................5
確保安裝成功. ...............................................5
Node.REPL................................................. 5
執行文件.......................................................... 6
NPM................................................................. 6
安裝模塊...........................................................7
自定義模塊. .......................................................8
安裝二進製工具包. ..................................................9
瀏覽NPM倉庫. .......................................................9
小結................................................................. 10
CHAPTER 2 JavaScript概覽.........................................11
介紹.......................................................... 11
JavaScript基礎..................................................... 12
類型. ......................................................... 12
類型的睏惑. ............................................... 12
函數. .......................................................... 13
THIS、FUNCTION #CALL以及FUNCTION#APPLY.................... 14
函數的參數數量. ........................... 14
閉包. ........................................................ 14
類. .............................................................. 15
繼承. ..................................................... 16
TRY.{}.CATCH.{}...................................... 17
v8中的JavaScript............................... 17
OBJECT#KEYS....................................................... 18
ARRAY#ISARRAY................................................ 18
數組方法................................................. 18
字符串方法.. .................................................... 19
JSON............................................................. 19
FUNCTION#BIND....................................................... 19
FUNCTION#NAME.............................................. 19
_PROTO_(繼承). ............................................ 20
存取器....................................................... 20
小結.............................................................. 21
CHAPTER 3 阻塞與非阻塞IO................................. 23
能力越強,責任就越大................................................. 23
阻塞. ............................................................. 25
單綫程的世界. ............................................... 27
錯誤處理..................................................... 29
堆棧追蹤................................................ 30
小結............................................................... 32
CHAPTER 4 Node中的JavaScript ..................................... 33
global對象....................................................... 33
實用的全局對象. ................................................ 34
模塊係統............................................................ 34
絕對和相對模塊. .................................................. 35
暴露API. ............................................................... 37
事件......................................................... 38
buffer............................................................... 40
小結................................................................... 41
PART Ⅱ Node重要的API
CHAPTER 5 命令行工具(CLI)以及FS API:首個Node應用................... 45
需求................................................. 45
編寫首個Node程序...................................... 46
創建模塊.............................................. 46
同步還是異步. ............................ 47
理解什麼是流(stream)................................... 49
輸入和輸齣. .......................................................... 50
重構. ........................................ 53
用fs進行文件操作. .............................. 55
對CLI一探究竟. ................................................. 56
argv.................................................... 57
工作目錄...................................... 57
環境變量........................................... 58
退齣. ............................................... 58
信號. .......................................................... 58
ANSI轉義碼............................................ 59
對fs一探究竟. ................................................. 59
Stream......................................................... 59
監視. .......................................... 60
小結...................................................... 61
CHAPTER 6 TCP ........................................... 63
TCP有哪些特性. ..................................................... 64
麵嚮連接的通信和保證順序的傳遞. ........................... 64
麵嚮字節........................................ 65
可靠性............................................... 65
流控製......................................... 65
擁堵控製.............................................. 65
Telnet................................................................ 65
基於TCP的聊天程序............................................... 68
創建模塊..................................... 68
理解NET.SERVER.API........................ 68
接收連接....................................... 70
data事件. ...................................................... 71
狀態以及記錄連接情況. ........................................ 73
圓滿完成此程序. ............................................ 75
一個IRC客戶端程序.......................................... 77
創建模塊.............................................. 77
理解NET#STREAM.API.. ......................................... 78
實現部分IRC協議. .................................................. 78
測試實際的IRC服務器. .................................. 78
小結................................................................. 79
CHAPTER 7 HTTP .................................................. 81
HTTP結構......................................................... 81
頭信息. ...................................................... 82
連接.............................................................. 87
一個簡單的Web服務器.................................................. 88
創建模塊....................................... 88
輸齣錶單.................................................... 88
method和URL. ........................................... 90
數據. .............................................. 92
整閤. ................................................ 94
讓程序更健壯. ..................................... 95
一個Twitter.Web客戶端......................................... 96
創建模塊....................................... 96
發送一個簡單的HTTP請求. ...................... 97
發送數據......................................... 98
獲取推文................................................. 99
superagent來拯救.............................................. 102
使用up重啓HTTP服務器..................................... 103
小結............................................. 104
PART Ⅲ Web開發
CHAPTER 8 Connect .............................. 107
使用HTTP構建一個簡單的網站. ....................................... 108
通過Connect實現一個簡單的網站...................................... 111
中間件. ................................................. 112
書寫可重用的中間件. .........................114
static中間件. .............................................119
query中間件. .......................................120
logger中間件................................................... 120
body.parser中間件. .................................122
cookie.........................................................125
會話(session). ......................................126
Redis.session..................................................131
methodOverride中間件. ...........................132
basicAuth中間件. ......................................132
小結.............................................................. 134
CHAPTER 9 Express..................................................135
一個小型Express應用. ...................................... 135
創建模塊..............................................136
HTML...........................................................136
SETUP..........................................................137
定義路由............................................137
查詢. .................................................140
運行. .....................................................141
設置......................................................... 142
模闆引擎...................................................... 143
錯誤處理........................................................ 144
快捷方法................................................. 144
路由................................................ 146
中間件. .................................................... 148
代碼組織策略. ......................................... 149
小結................................................. 151
CHAPTER 10 WebSocket .................. 153
Ajax.............................................. 153
HTML5.WebSocket............................................... 156
一個ECHO示例. ......................................................... 157
初始化項目. .............................................157
建立服務器. ..................................................158
建立客戶端. ......................................159
運行示例程序. ...................................160
鼠標光標.......................................... 161
初始化示例程序. .........................................161
建立服務器. ............................................161
建立客戶端. .....................................164
運行示例程序. .........................................166
麵臨一個挑戰. ............................................. 166
關閉並不意味著斷開連接. .............................166
JSON...........................................167
重連. ...................................................167
廣播. ................................................167
WebSocket屬於HTML5:早期瀏覽器不支持. ..........................167
解決方案.................................................167
小結............................................................. 167
CHAPTER 11 Socket.IO.............................................169
傳輸................................................. 170
斷開.VS.關閉. ............................................170
事件. ..........................................170
命名空間..............................................171
聊天程序................................................. 172
初始化程序. .......................................172
構建服務器. ..........................................172
構建客戶端. .......................................173
事件和廣播. ........................................175
消息接收確認. .................................179
一個輪流做DJ的應用................................ 180
擴展聊天應用. ...........................................181
集成Grooveshark.API. ...............................182
播放歌麯...............................................185
小結.................................................... 190
PART Ⅳ 數據庫
CHAPTER 12 MongoDB.......................193
安裝.................................................. 195
使用MongoDB:一個用戶認證的例子. .................................. 195
構建應用程序. .......................................195
創建Express.App.. ..............................196
連接MongoDB. ...................................200
創建文檔......................................201
查找文檔..................................203
身份驗證中間件. ..................................204
校驗.. ..............................................205
原子性..............................................206
安全模式................................206
Mongoose介紹......................................... 206
定義模型........................................207
定義嵌套的鍵. ..........................208
定義嵌套文檔. .....................................209
構建索引..........................................209
中間件.................................................209
探測模型狀態.. ...............................210
查詢. ..............................................210
擴展查詢........................................210
排序.. ........................................211
選擇. ......................................................211
限製.. .....................................211
跳過. .........................................211
自動産生鍵. ...............................211
轉換. ..............................................212
一個使用Mongoose的例子........................................ 212
構建應用.................................212
重構. ..............................213
建立模型.................................213
小結.......................................... 215
CHAPTER 13 MySQL...........................................217
node-mysql........................................ 217
初始化項目. .......................................217
Express應用. ...................................218
連接MySQL. .....................................219
初始化腳本. .......................................220
創建數據................................................224
獲取數據.....................................228
sequelize............................................ 229
初始化sequelize. ................................230
初始化Express應用. ....................................230
連接sequelize. .........................233
定義模型和同步. ........................... 234
創建數據.................................236
獲取數據......................................238
刪除數據..............................239
完整地完成應用. ...............................240
小結.......................................... 241
CHAPTER 14 Redis......................................... 243
安裝Redis............................................... 244
Redis查詢語言. ............................................... 245
數據類型............................................. 245
字符串. ...................................246
哈希. .................................................246
列錶. ......................................... 248
數據集. .....................................249
有序數據集. .........................................249
Redis和Node. .......................................... 249
使用node-redis實現一個社交圖譜. .............250
小結......................................... 259
PART Ⅴ 測試
CHAPTER 15 代碼共享 ................................. 263
什麼樣的代碼可以共享........................................... 263
書寫兼容的JavaScript代碼................................ 264
導齣模塊......................................................264
模擬實現ECMA.API. ................................265
模擬實現Node.API. ......................................267
模擬實現瀏覽器端API. ...............................267
跨瀏覽器的繼承實現. ...........................268
集成到一起:browserbuild. ...................... 268
基礎案例....................................269
小結......................................... 271
CHAPTER 16 測試................................... 273
簡單測試........................................ 273
測試目標............................................. 274
測試策略................................... 274
測試程序...................................................275
expect.js................................................. 276
API一覽. .........................................276
Mocha................................................. 278
測試異步代碼. ..................................279
BDD風格. ................................281
TDD風格. .......................................281
export風格. .................................282
在瀏覽器端使用Mocha. ...................................282
小結.................................... 284
索引 ...................................... 285
· · · · · · (
收起)