2021年Node.js開發人員學習路線圖

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Node.js 自發布以來,已成爲業界重要破局者之一。Uber、Medium、PayPal 和沃爾瑪等大型企業,紛紛將技術棧轉向 Node.js。Node.js 支持開發功能強大的應用,例如實時追蹤 App、視頻 \/ 文本聊天引擎、社交媒體 App 等,當前已成爲開發人員熱衷的一項技能。本文作者基於自身實施經歷,給出一張 Node.js 學習路線圖。建議開發人員考慮深入掌握 Node.js 之前,必須明確自己構建的目標,否則容易半途而廢。目標導向有助於在學習中聚焦關鍵技能,而非糾結於是否值得去學習。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"必備技能"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"JavaScript"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於一名前端開發人員,在考慮掌握後端技能時,無需花費大量的精力學習去 JavaScript。而對於完全小白,如果想要在儘可能短的時間內掌握 Node.js,在深入前必須領會如下概念:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"箭頭函數(Arrow Functions)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"類型(Types)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"表達式(Expressions)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"函數(Functions)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"語法結構(Lexical Structures)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"this"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"循環(Loops)和作用域(Scope)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數組對象(Arrays)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"字面量模板(Template Literals)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"嚴格模式(Strict Mode)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ES6\/ES7"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此外,Node.js 中涉及大量的異步編程處理,推薦掌握如下概念:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"定時器(Timers)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Promises"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"閉包(Closures)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"事件循環(Event Loop)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"異步編程(Async programming)和回調(callbacks)"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"npm 軟件包管理"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Node 軟件包管理(Node Package Manager,npm)提供當前規模最大的註冊軟件庫,其中提供 80 多萬種軟件包。正確使用 npm,可極大地降低軟件包管理的複雜度,非常便於解決應用開發中的依賴問題。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"npm 提供三個組成模塊:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"命令行接口(Command Line Interface,CLI):CLI 是大部分開發人員的首選方式,提供本機終端環境運行。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"註冊軟件庫(Registry):提供大規模開放式 JavaScript 軟件和元信息數據庫。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Web 站點:可查找新的軟件包,並提供其它一些 npm 功能。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"npm 還可管理各版本的代碼及依賴。如果使用 npx,無需下載軟件包即可運行軟件包。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Node.js 基礎知識"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"事件發射器(Event Emitter)"},{"type":"text","text":":做爲 Node.js 中的對象,Event Emitter 在操作執行完成後發送消息,觸發特定的事件。開發人員也可編寫代碼,監聽 Event Emitter 發出的事件。例如,一旦完成特定的前端操作,諸如鼠標點擊、按鍵和鼠標移動等交互操作,需在後端做進一步處理。這時後端的 Node.js 環境使用 EventEmitter 類,構建相應的事件處理模塊,用於處理操作事件。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"回調"},{"type":"text","text":"(Callback):回調是特定任務執行完成後調用的函數,不影響其它代碼的同時執行,避免了異步處理產生阻塞。鑑於 Node.js 中需處理大量的異步任務,因此回調無處不在。回調是實現應用無縫快速執行的關鍵,其運作機制如下圖所示:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/00\/00f4992880d3afd6cd61c0cde6351ab1.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Buffer 類"},{"type":"text","text":":設計用於處理原始二進制數據的 Node.js 類,操作 V8 引擎外分配的內存。Buffer 類實現爲大小不可調整的整數數組,並提供一整套二進制數據操作方法。例如,對於表示範圍在 0 到 255 之間字節值的內存中整數,使用 console.log() 輸出該 Buffer 實例,會給出一系列十六進制值。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"模塊系統(Module System)"},{"type":"text","text":":使用 Node.js 生態系統提供的模塊,可實現一些複雜功能。模塊是可複用的 JavaScript 代碼,實現特定的功能。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"開發技能"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"版本管理系統"},{"type":"text","text":":掌握 git、GitHub 等的使用。開發中,應儘量避免交叉修改代碼導致的更改不可逆。因此,在大型項目中需使用版本控制系統管理。要熟悉版本控制系統的使用,開發人員應該具備紮實的基礎知識。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"HTTP\/HTTPS 協議"},{"type":"text","text":":一位優秀的 Node.js 開發人員,應具備傳輸協議數據傳輸的基礎知識,因爲每位後端開發人員都需要深入理解 HTTP\/HTTPS 的工作機制。HTTPS 使用稱爲 TLS(Transport Layer Security)的加密協議加密通信。後端環境中有大量要學習的知識點,這對於 Web 小白是頗具難度的。簡而言之,基本的 Web 通信主要包括六種請求方法:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"GET: 獲取資源的表示;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"POST: 創建新資源;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PUT: 更新資源;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PATCH: 局部修改資源;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"DELETE: 刪除 URL 指定的資源"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"OPTIONS: 請求指定 URL\/ 服務器所支持的通信。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"Web 框架"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"注意:本文僅列出了部分推薦 Web 框架。使用 Node.js 構建個人項目時,爲降低學習難度,推薦從中選定一種框架,否則學習難度很高。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Express.js"},{"type":"text","text":":提供構建應用所需的最小化接口和工具,非常靈活易用,大量 npm 模塊可直接插入 Expresss 使用。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Meteor.js"},{"type":"text","text":":一種構建 JavaScript 應用的萬事通框架,提供內建的 MongoDB,支持 GraphQL。運行 meteor create myapp,即可生成一個具有 MongoDB 後端的 HTML\/JavaScript 頁面。使用 Meteor.js 可有效助降低項目開發時間,並簡化項目的維護。當然如果只是構建一個簡單的 Web 應用,還是推薦使用 Express。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Sails.js"},{"type":"text","text":":一種支持快速構建 REST API、單頁應用(SPA)和實時 APP 的 MVC 框架。如果開發人員考慮實操一些重要技能,例如使用 WebSockets 支持實時操作,使用按約定編程(convention over configuration)方法等,推薦學習 Sails.js。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Koa.js"},{"type":"text","text":":如果開發人員考慮構建一個經得起時間考驗、易於維護的魯棒應用,Koa.js 無疑是很好的選擇。Koa 應用實現爲包含一組中間件函數數組的對象,其中函數以堆棧方式執行。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Nest.js"},{"type":"text","text":":該框架繼承了 Angular 的理念,使用 TypeScript 構建,並且在底層使用了 Express.js,因此兼容大多數 Express 中間件。Nest 提供很好的模塊化結構,代碼組織在不同模塊中,進而構建高效、良好擴展的應用。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"數據庫管理"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"學習 Node.js 需要掌握大量的後端技能。對於一名小白,開始可選擇 MySQL 等數據庫。只有釐清後端系統設計的基礎知識,才能根據項目的需求,考慮在 MySQL 等基本 SQL 數據庫之外選取後端。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"注意:關係數據庫依然是主流。例如,在建模產品、類比、標籤等時依然主要使用關係表結構。類似於電子表格,關係表由行和列組成。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"關係數據庫管理系統"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"SQL Server"},{"type":"text","text":":微軟的關係數據庫產品,支持標準 ANSI SQL,也提供產品獨有的 SQL 實現。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"MySQL"},{"type":"text","text":":一款優秀的關係數據庫管理系統,時由 Oracle 提供的開源後端軟件,具備按需改進代碼的靈活性。MySQL 可很好地替代 Oracle、Microsoft SQL server 等商業數據庫產品。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"PostgreSQL"},{"type":"text","text":":具有大規模開發團隊支持的開源產品,可運行在 Linux、UNIX 和 Windows 等大多數主流操作系統上。PostgreSQL 支持絕大多數標準 SQL 查詢,還提供複雜 SQL 查詢、外鍵、觸發器、事務、MVCC、流複製等特性。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"MariaDB"},{"type":"text","text":":MySQL 的改進版,額外內建了多種特性、安全和性能改進。簡而言之,MariaDB 性能優於 MySQL,推薦在大型應用中使用 MariaDB。例如,MariaDB 的大型連接池支持超過 20 萬的併發連接,顯著優於 MySQL。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"雲數據庫服務"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Azure CosmosDB"},{"type":"text","text":":一種全球分佈式數據庫服務,支持遠程管理數據。對於大型應用,雲數據庫在擴展型和可管理性上具有優勢。Microsoft Azure 完全簡化了可擴展和分佈能力,在同一後端上支持多種數據模型,即可同時用於文檔、鍵值、關係和圖模型。該服務不依賴於任何模式,因此可稱爲 NoSQL 數據庫,但可使用支持 ACID 交易的查詢語言。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Amazon DynamoDB"},{"type":"text","text":":非常適用於具有 SQL 經驗的用戶,提供全託管 NoSQL 數據庫服務,具有高性能,可預測,擴展性很好。DynamoDB 支持創建關係表,可存儲並檢索任何規模的數據,提供任何服務等級的請求。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"NoSQL 數據庫"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"MongoDB"},{"type":"text","text":":面向文檔的 NoSQL 數據庫,適用於大規模數據存儲。類似於表是關係數據庫的基礎,MongoDB 使用集合(Collection)和文檔(Document)。其中,文檔包含了鍵值對,是 MongoDB 的基本數據單元。集合包含一系列文檔和函數,對標關係數據庫中的表。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Redis"},{"type":"text","text":":可用於數據庫、緩存和消息代理(Message Broker)。Redis 使用字符串、哈希、列表、集合、位圖、hyperloglog 和時空索引等數據結構,以鍵值形式存儲數據。下面舉例說明:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"假設應用必須處理授權用戶的不同操作。每次驗證用戶身份,都必須獲取應用中訪問權限控制模塊的授權。實現此類安全機制的方案很多。例如,標準的 JOSE(JavaScript 對象簽名和加密)框架可確保應用數據的安全性。但面對多種授權時,應用同樣很難擴展。除了發送授權列表給用戶,另一種解決方案是將用戶授權以某種形式的數據庫存儲。授權以鍵值對(也稱爲令牌)形式提供,用戶必須提供鍵值進行驗證。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Apache Cassandra"},{"type":"text","text":":Facebook 創建的高度可擴展、高性能的分佈式數據庫,設計針對物理上分佈的海量數據,實現無單點故障的存儲。不同於其它關係數據庫系統,Cassandra 在分佈式設計上參考了 Amazon DynamoDB,數據模型使用 Google BigTable。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"LiteDB"},{"type":"text","text":":一款超輕量級、高性能的 .NET NoSQL 嵌入數據庫,實現無服務器的文檔存儲。LiteDB 使用於小型的桌面應用、Web 應用,可根據每個用戶的每個賬戶建立一個獨立數據庫。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"搜索引擎"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"注意:爲什麼需要了解搜索引擎技術,下面舉例說明。如果使用谷歌搜索引擎,它本身就是一個完整的 Web 應用。對於 Solr 和 ElasticSearch 等後端框架,它們會對所有類型數據集創建索引,進而在服務器提供搜索功能。Solr 支持百萬級用戶的搜索引擎網站。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"ElasticSearch"},{"type":"text","text":":一種基於 Apache Lucene 使用 Java 開發的搜索和分析引擎,實現海量數據的實時存儲和分析。其高性能來自於對索引而非文本的搜索,核心基於結構化文檔,而非關係表和模式,提供豐富的 REST API 存儲和搜索數據。ElasticSearch 可認爲是一臺處理 JSON 請求並返回 JSON 數據的服務器。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Solr"},{"type":"text","text":":提供包括字段搜索、布爾查詢、短語查詢、模糊查詢、語法檢查、自動填全等高級實時搜索功能。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"緩存"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"注意:緩存使用內存中存儲文件拷貝,降低網絡調用,提供更快的網絡響應。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"內存緩存"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"該技術大多數情況下使用服務器的內存,因此通常稱爲內存緩存。服務器的一部分內存用作緩存,存儲降低應用網絡調用所需的所有數據。Node.js 提供的節點緩存(node-cache)和內存緩存(memory-cache)軟件庫,很好地處理了 Node 服務器上的內存緩存。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"分佈式緩存"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分佈式緩存將多個網絡內存整合爲單一的內存數據存儲,進而用於緩存最終數據,提供對數據的快速訪問。該技術尤其適用於大規模數據和大量網絡調用的情況,通過在羣集中添加更多的服務器實現緩存容量的增量擴展和擴容。Redis 是目前最廣爲使用的 分佈式內存,推薦進一步瞭解 Memcached。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/e1\/e12a4908193d4f501d81178c9dcd0de6.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"模板引擎"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"模板引擎支持在應用開發中使用靜態模板文件,並在運行時替換模板文件中的變量爲實際值,生成發送給客戶的 HTML 文件。下面列出了一些廣爲使用的模板引擎。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Mustache.js"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Handlebars"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"EJS"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"實時通信"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Socket.io:對於起步接觸後端開發的學習者,瞭解 Socket.io 的實時通信需要補充很多知識,主要底層邏輯在客戶端和服務器之間。Socket.io 支持客戶和服務器間的雙向數據流,可視爲實現兩個終端間實時通信的同步數據流行爲。這需要客戶在瀏覽器支持 Socket.IO,並且服務器端繼承了 Socket.IO 軟件包,進而數據才能以 JSON 請求的形式發送。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"API 客戶端"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"REST"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 REST 提出之前,API 使用遠程過程調用(RPC)開發,類似於本地執行的代碼。期間許多技術使用了類似於 RPC 的技術棧,並未從根本上解決問題,直到 REST 提出以更好的方式構建基於 Web 的 API。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"REST 架構使用基本 HTTP 調用進行通信,避免了使用 COBRA、COM +,RPC 等複雜方式通信。在 REST 中,調用是基於消息的,依賴 HTTP 標準描述消息。在 Node.js 生態中,推薦使用 node-rest-client 和 Axios。這兩個軟件庫爲快速 Web 應用提供了很好的支持。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"GraphQL"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"GraphQL 可很好地替代 REST。它使用 API 優先爲客戶準確提供所請求的數據,是一種靈活並且對開發人員友好的替代方案,可使用 GraphiQL IDE 部署。GraphQL 具有多項優點,包括在不影響現有查詢情況下添加和禁用數據域,以及支持多種方式構建 API。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"測試"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"單元測試框架"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"單元測試實現各單元和組件的隔離測試。其中,單元可以是應用中的最小可測試代碼部分。下面列出 Node.js 的最好的單元測試框架:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Jest:一款由 Facebook 提供的測試框架,因其簡潔性而廣爲使用。Jest 相比其它所有測試框架而言具有最好的文檔,支持並行測試,這意味可使用單獨進程獨立運行各個測試,實現性能最大化。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Mocha:爲 Node 應用提供原始標準的單元測試框架,支持回調等異步操作,支持使用高度可擴展和自定義斷言的 Promise。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Chai:支持與 Mocha 一同使用,可做爲 Node.js 的 TDD\/BDD 斷言庫,可匹配任何基於 JavaScript 的測試框架。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"模擬測試(Mocking)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"單元測試的規模越小越好,並儘可能輕量級執行。但在一些情況下,測試對象存在對其他對象的依賴。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"例如,對於需要與域服務器或 Web Service 通信的對象,無法執行快速、輕量級的測試,這時就需要 Mocking 測試。運行 Mocking 測試不需要任何實際數據庫,或是任何類型的連接,只返回給出預期結果的對象。Mocking 測試只使用一些基本對象,模擬給出實際測試結果,因此可擺脫所有侷限更快地運行測試。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"推薦閱讀:"},{"type":"text","text":" 下面資料分別介紹瞭如何使用 Sinon 和 Jasmine 實現 Mocking 測試:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Sinon"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/stackabuse.com\/using-mocks-for-testing-in-javascript-with-sinon-js\/","title":"","type":null},"content":[{"type":"text","text":"https:\/\/stackabuse.com\/using-mocks-for-testing-in-javascript-with-sinon-js\/"}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Jasmine"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/eclipsesource.com\/blogs\/2014\/03\/27\/mocks-in-jasmine-tests\/","title":"","type":null},"content":[{"type":"text","text":"https:\/\/eclipsesource.com\/blogs\/2014\/03\/27\/mocks-in-jasmine-tests\/"}]}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Node.js 軟件庫推薦:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Async.js"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PM2"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Commander.js"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Nodemailer"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原文鏈接:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/js.plainenglish.io\/node-js-developer-roadmap-for-2021-2ae9c057bff4","title":"","type":null},"content":[{"type":"text","text":"https:\/\/js.plainenglish.io\/node-js-developer-roadmap-for-2021-2ae9c057bff4"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章