Enviar búsqueda
Cargar
All about NodeJS
•
Descargar como PPTX, PDF
•
18 recomendaciones
•
1,994 vistas
Hsu Ping Feng
Seguir
Tecnología
Denunciar
Compartir
Denunciar
Compartir
1 de 81
Descargar ahora
Recomendados
Nodejs introduce - using Socket.io
Nodejs introduce - using Socket.io
Caesar Chi
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
GO LL
Node.js中间件 connect模块深入浅出
Node.js中间件 connect模块深入浅出
Eric Xiao
Node.js從無到有 基本課程
Node.js從無到有 基本課程
Simon Su
Node.js 淺談socket.io
Node.js 淺談socket.io
Simon Su
學好 node.js 不可不知的事
學好 node.js 不可不知的事
Ben Lue
Koa 正在等一個人
Koa 正在等一個人
Fred Chien
Network and Multitasking
Network and Multitasking
yarshure Kong
Recomendados
Nodejs introduce - using Socket.io
Nodejs introduce - using Socket.io
Caesar Chi
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
GO LL
Node.js中间件 connect模块深入浅出
Node.js中间件 connect模块深入浅出
Eric Xiao
Node.js從無到有 基本課程
Node.js從無到有 基本課程
Simon Su
Node.js 淺談socket.io
Node.js 淺談socket.io
Simon Su
學好 node.js 不可不知的事
學好 node.js 不可不知的事
Ben Lue
Koa 正在等一個人
Koa 正在等一個人
Fred Chien
Network and Multitasking
Network and Multitasking
yarshure Kong
前端自動化工具
前端自動化工具
國昭 張
淺談 Groovy 與 Gradle
淺談 Groovy 與 Gradle
Justin Lin
Docker進階探討
Docker進階探討
國昭 張
D2_node在淘宝的应用实践_pdf版
D2_node在淘宝的应用实践_pdf版
Jackson Tian
Node.js 進攻桌面開發
Node.js 進攻桌面開發
Fred Chien
用最潮的 Java script 盡情開發 kde qt 程式
用最潮的 Java script 盡情開發 kde qt 程式
Fred Chien
Java script 全面逆襲!使用 node.js 打造桌面環境!
Java script 全面逆襲!使用 node.js 打造桌面環境!
Fred Chien
Node分享 展烨
Node分享 展烨
tb-vertical-guide
使用Javascript及HTML5打造協同運作系統
使用Javascript及HTML5打造協同運作系統
Hsu Ping Feng
不一樣的Web server... coServ
不一樣的Web server... coServ
Ben Lue
Node.js 入門 - 前端工程開發實務訓練
Node.js 入門 - 前端工程開發實務訓練
Joseph Chiang
Spock:願你的測試長長久久、生生不息
Spock:願你的測試長長久久、生生不息
Shihpeng Lin
Browser vs. Node.js Jackson Tian Shanghai
Browser vs. Node.js Jackson Tian Shanghai
Jackson Tian
Npm 套件管理 & 常用開發工具介紹
Npm 套件管理 & 常用開發工具介紹
wantingj
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
Will Huang
Getting started with test automation
Getting started with test automation
Ivan Wei
Docker實務
Docker實務
國昭 張
再生龍於雲端環境之應用
再生龍於雲端環境之應用
Chenkai Sun
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
Will Huang
認識那條鯨魚 Docker 初探
認識那條鯨魚 Docker 初探
仲昀 王
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
Microservices and Seneca at RomaJS group
Microservices and Seneca at RomaJS group
Luca Lanziani
Más contenido relacionado
La actualidad más candente
前端自動化工具
前端自動化工具
國昭 張
淺談 Groovy 與 Gradle
淺談 Groovy 與 Gradle
Justin Lin
Docker進階探討
Docker進階探討
國昭 張
D2_node在淘宝的应用实践_pdf版
D2_node在淘宝的应用实践_pdf版
Jackson Tian
Node.js 進攻桌面開發
Node.js 進攻桌面開發
Fred Chien
用最潮的 Java script 盡情開發 kde qt 程式
用最潮的 Java script 盡情開發 kde qt 程式
Fred Chien
Java script 全面逆襲!使用 node.js 打造桌面環境!
Java script 全面逆襲!使用 node.js 打造桌面環境!
Fred Chien
Node分享 展烨
Node分享 展烨
tb-vertical-guide
使用Javascript及HTML5打造協同運作系統
使用Javascript及HTML5打造協同運作系統
Hsu Ping Feng
不一樣的Web server... coServ
不一樣的Web server... coServ
Ben Lue
Node.js 入門 - 前端工程開發實務訓練
Node.js 入門 - 前端工程開發實務訓練
Joseph Chiang
Spock:願你的測試長長久久、生生不息
Spock:願你的測試長長久久、生生不息
Shihpeng Lin
Browser vs. Node.js Jackson Tian Shanghai
Browser vs. Node.js Jackson Tian Shanghai
Jackson Tian
Npm 套件管理 & 常用開發工具介紹
Npm 套件管理 & 常用開發工具介紹
wantingj
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
Will Huang
Getting started with test automation
Getting started with test automation
Ivan Wei
Docker實務
Docker實務
國昭 張
再生龍於雲端環境之應用
再生龍於雲端環境之應用
Chenkai Sun
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
Will Huang
認識那條鯨魚 Docker 初探
認識那條鯨魚 Docker 初探
仲昀 王
La actualidad más candente
(20)
前端自動化工具
前端自動化工具
淺談 Groovy 與 Gradle
淺談 Groovy 與 Gradle
Docker進階探討
Docker進階探討
D2_node在淘宝的应用实践_pdf版
D2_node在淘宝的应用实践_pdf版
Node.js 進攻桌面開發
Node.js 進攻桌面開發
用最潮的 Java script 盡情開發 kde qt 程式
用最潮的 Java script 盡情開發 kde qt 程式
Java script 全面逆襲!使用 node.js 打造桌面環境!
Java script 全面逆襲!使用 node.js 打造桌面環境!
Node分享 展烨
Node分享 展烨
使用Javascript及HTML5打造協同運作系統
使用Javascript及HTML5打造協同運作系統
不一樣的Web server... coServ
不一樣的Web server... coServ
Node.js 入門 - 前端工程開發實務訓練
Node.js 入門 - 前端工程開發實務訓練
Spock:願你的測試長長久久、生生不息
Spock:願你的測試長長久久、生生不息
Browser vs. Node.js Jackson Tian Shanghai
Browser vs. Node.js Jackson Tian Shanghai
Npm 套件管理 & 常用開發工具介紹
Npm 套件管理 & 常用開發工具介紹
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
Getting started with test automation
Getting started with test automation
Docker實務
Docker實務
再生龍於雲端環境之應用
再生龍於雲端環境之應用
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
認識那條鯨魚 Docker 初探
認識那條鯨魚 Docker 初探
Destacado
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
Microservices and Seneca at RomaJS group
Microservices and Seneca at RomaJS group
Luca Lanziani
Node Interactive : 7 years, 7 design patterns, will node continue to outshine
Node Interactive : 7 years, 7 design patterns, will node continue to outshine
Shubhra Kar
The Seneca Pattern at EngineYard Distill 2013 Conference
The Seneca Pattern at EngineYard Distill 2013 Conference
Richard Rodger
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
Richard Rodger
Writing Test Cases with PHPUnit
Writing Test Cases with PHPUnit
Shouvik Chatterjee
NodeJS Microservices, Built it Now, Scale it Later!
NodeJS Microservices, Built it Now, Scale it Later!
Lalit Shandilya
Richard rodger technical debt - web summit 2013
Richard rodger technical debt - web summit 2013
Richard Rodger
NodeJS
NodeJS
.toster
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
Nurul Ferdous
Nodejs in Production
Nodejs in Production
William Bruno Moraes
Building Web Apps & APIs With Node JS
Building Web Apps & APIs With Node JS
Lohith Goudagere Nagaraj
How to scale and deploy NodeJS app
How to scale and deploy NodeJS app
Yacobus Reinhart
NodeJS security - still unsafe at most speeds - v1.0
NodeJS security - still unsafe at most speeds - v1.0
Dinis Cruz
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Valeri Karpov
Java script at backend nodejs
Java script at backend nodejs
Amit Thakkar
High Performance NodeJS
High Performance NodeJS
Dicoding
Testing NodeJS Security
Testing NodeJS Security
Jose Manuel Ortega Candel
NodeJS - Server Side JS
NodeJS - Server Side JS
Ganesh Kondal
Why Reactive Architecture Will Take Over The World (and why we should be wary...
Why Reactive Architecture Will Take Over The World (and why we should be wary...
Steve Pember
Destacado
(20)
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Microservices and Seneca at RomaJS group
Microservices and Seneca at RomaJS group
Node Interactive : 7 years, 7 design patterns, will node continue to outshine
Node Interactive : 7 years, 7 design patterns, will node continue to outshine
The Seneca Pattern at EngineYard Distill 2013 Conference
The Seneca Pattern at EngineYard Distill 2013 Conference
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
Writing Test Cases with PHPUnit
Writing Test Cases with PHPUnit
NodeJS Microservices, Built it Now, Scale it Later!
NodeJS Microservices, Built it Now, Scale it Later!
Richard rodger technical debt - web summit 2013
Richard rodger technical debt - web summit 2013
NodeJS
NodeJS
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
Nodejs in Production
Nodejs in Production
Building Web Apps & APIs With Node JS
Building Web Apps & APIs With Node JS
How to scale and deploy NodeJS app
How to scale and deploy NodeJS app
NodeJS security - still unsafe at most speeds - v1.0
NodeJS security - still unsafe at most speeds - v1.0
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Java script at backend nodejs
Java script at backend nodejs
High Performance NodeJS
High Performance NodeJS
Testing NodeJS Security
Testing NodeJS Security
NodeJS - Server Side JS
NodeJS - Server Side JS
Why Reactive Architecture Will Take Over The World (and why we should be wary...
Why Reactive Architecture Will Take Over The World (and why we should be wary...
Similar a All about NodeJS
猴子也能懂的Node.js
猴子也能懂的Node.js
HopenglishRD
Introduction to NodeJS
Introduction to NodeJS
TechParty@UIC
Full stack-development with node js
Full stack-development with node js
Xuefeng Zhang
Nodejs部门分享
Nodejs部门分享
zffl
51 cto下载 51cto信息图:openshift vs cloudfoundry
51 cto下载 51cto信息图:openshift vs cloudfoundry
Hong Cai
Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2
twMVC
twMVC#02 | ASP.NET MVC 從無到有
twMVC#02 | ASP.NET MVC 從無到有
twMVC
J S教材
J S教材
yiditushe
NODEjs Lesson1
NODEjs Lesson1
3dmodeldiy
Js高级技巧
Js高级技巧
fool2fish
Node js feat pegasus
Node js feat pegasus
cnfi
这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit
LainZQ
课题二:Node.js那些事儿
课题二:Node.js那些事儿
Liu Allen
Nodejs api server_implement
Nodejs api server_implement
Chi-wen Sun
React Native + Redux
React Native + Redux
Ch Rick
Lab01 cloud project
Lab01 cloud project
Jeff Chu
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Gelis Wu
Asp.net 5 新功能與變革
Asp.net 5 新功能與變革
Gelis Wu
000 北京圣思园教育科技有限公司第一期面授培训大纲
000 北京圣思园教育科技有限公司第一期面授培训大纲
ArBing Xie
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
裕波 周
Similar a All about NodeJS
(20)
猴子也能懂的Node.js
猴子也能懂的Node.js
Introduction to NodeJS
Introduction to NodeJS
Full stack-development with node js
Full stack-development with node js
Nodejs部门分享
Nodejs部门分享
51 cto下载 51cto信息图:openshift vs cloudfoundry
51 cto下载 51cto信息图:openshift vs cloudfoundry
Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2
twMVC#02 | ASP.NET MVC 從無到有
twMVC#02 | ASP.NET MVC 從無到有
J S教材
J S教材
NODEjs Lesson1
NODEjs Lesson1
Js高级技巧
Js高级技巧
Node js feat pegasus
Node js feat pegasus
这年头,你只需要懂Node webkit
这年头,你只需要懂Node webkit
课题二:Node.js那些事儿
课题二:Node.js那些事儿
Nodejs api server_implement
Nodejs api server_implement
React Native + Redux
React Native + Redux
Lab01 cloud project
Lab01 cloud project
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Asp.net 5 新功能與變革
Asp.net 5 新功能與變革
000 北京圣思园教育科技有限公司第一期面授培训大纲
000 北京圣思园教育科技有限公司第一期面授培训大纲
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
All about NodeJS
1.
瞭解NodeJS開發技術 by Fillano
2.
課程主要內容 NodeJS的背景知識 如何撰寫NodeJS程式
幾個codeexample展示與說明 在Windows環境中執行NodeJS 如何找到更多資源
3.
NodeJS的背景知識 作者、Javascript、V8及其它
4.
什麼是NodeJS 它主要是一個伺服器端的Javascript環境 它提供了符合CommonJS1.0規格的模組機制,擴充功能非方便
只要能使用模組來擴充功能,實際使用上並不限於伺服器程式
5.
什麼是NodeJS 舊瓶裝新酒 1996–NetscapeLivewireinNetscapeEnterpriseServer
ASPwithJscript,Jscript.NET MozillaRhino Flowscript for Apache Cocoon 2.1 JavascriptWebflow for Spring Helma (http://helma.org) RingoJS(http://ringojs.org/)
6.
什麼是NodeJS 舊瓶裝新酒 MozillaSpiderMonkey
AptanaJaxer(http://jaxer.org/) couchDB (RESTful API) GoogleV8 v8cgi(http://code.google.com/p/v8cgi/) v8juice(http://code.google.com/p/v8-juice/) wikipedia: Comparison of server-side JavaScript solutions
7.
8.
類似v8juice與jslib(http://jslib.mozdev.org/)
9.
10.
vsphp (benchmarking nodejs
basic performance tests against apache-php)
11.
vsruby(express vs sinatra
benchmarks)
12.
13.
AST:將Javascript剖析成抽象語法樹
14.
GenericCodeGen:直接產生尚未最佳化的機器碼執行
15.
目前使用的最佳化技術Cranshaft
16.
執行時期追蹤與Profiling
17.
將型別資訊紀錄在相關AST節點中
18.
OptimizedCodeGen
19.
20.
輪詢:每隔一段時間詢問系統是否有結果
21.
22.
Linux:epoll
23.
BSD:kqueue
24.
25.
Eventloops(event-machine, gearman…)
26.
27.
28.
29.
30.
31.
最新版本的Windows可執行檔下載
32.
33.
wiki:重點-如何在不同作業系統中編譯NodeJS
34.
35.
36.
37.
所有事件都是在一個eventloop依序執行
38.
39.
40.
支援child_process
41.
支援IOCP
42.
可動態載入的原生模組
43.
其它
44.
支援VisualC++
45.
之前只能在Cygwin及MSYS環境中編譯
46.
47.
支援MicrosoftWindows的I/OCompletionPort機制
48.
讓NodeJS抽換掉對於libeio,libevent,libev等的直接依賴
49.
50.
最簡單的程式範例helloworld伺服器 一頁就放的下的程式 var
http = require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World.'); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/');
51.
最簡單的程式範例helloworld加上ExpressFramework 一頁就放的下的程式 var
express = reuqire('express'), app=express.createServer(); app.get('/',function(req,res){ res.send('Hello World.'); }); app.listen(3000);
52.
53.
54.
55.
56.
接下來,用eventloop的方式執行所有事件函數,直到結束
57.
如果在瀏覽器中,可以利用動態新增script tag的方式,再次執行載入的script中GlobalContext中的程式碼,不過在NodeJS不會有這個狀況發生
58.
59.
60.
61.
Intel的計畫,讓Javascript可以在多核心環境中進行平行處理
62.
https://github.com/RiverTrail/RiverTrail
63.
64.
Javascript背景知識事件與callback函數 在瀏覽器中,通常很少超過兩層 varelem=document.getElementById(‘target’);
elem.addEventListener(‘click’,function(e){ req.onreadystatechange=function(){ if(this.readyState===4&&this.status===200){ varthat=this; window.setTimeout(function(){ alert(that.responseTest) },500) } } },false);
65.
Javascript背景知識事件與callback函數 在NodeJS環境中,有非常多的操作是用callback來完成,例如這一段mongo db的範例
varp_client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}), {'pk':CustomPKFactory}); p_client.open(function(err, p_client) { p_client.dropDatabase(function(err, done) { p_client.createCollection('test_custom_key', function(err, collection) { collection.insert({'a':1}, function(err, docs) { collection.find({'_id':newObjectID("aaaaaaaaaaaa")}, function(err, cursor) { cursor.toArray(function(err, items) { test.assertEquals(1, items.length); p_client.close(); });});});});});});
66.
67.
所以常常在callbacks中使用其他功能,就需要另外加一層callbacks
68.
69.
70.
71.
利用立即執行的匿名函數,把在Global Scope執行的程式包裝起來
72.
73.
74.
某些操作在Javascript中並沒有非同步執行的版本,例如JSON.parse/stringify,而這些操作比較花時間。這時可以找一找是否有人實作非同步的版本(模組)
75.
76.
某些Javascript函數,無法最佳化,所以使用到的話…
77.
78.
需要預先安裝Python及GCC4.0以上
79.
在nodejs.org網站取得原始碼
80.
解開後依序執行./configure、make
81.
82.
安裝Cygwin或是mingw+msys環境,還是需要Python及GCC4.0以上
83.
解開後依序執行./configure、make
84.
需要安裝到系統中時,執行make install
85.
如果需要在純windows環境中執行node.exe,還需要把Cygwin或是msys提供的一些dll檔複製到同一個目錄
86.
87.
V0.5.6之後,可以直接使用Microsoft Visual C++
2010來編譯,不過這個開發版本尚未釋出
88.
89.
需要預先安裝curl
90.
參考npmjs.org首頁上提供的方式,執行one line install
91.
Windows環境
92.
目前在Windows環境中還無法執行npm
93.
但是可利用NODE_PATH環境變數指定模組的預設路徑
94.
到search.npmjs.org網站上尋找要安裝的模組
95.
96.
開發NodeJS程式Global Scope環境 結果可以看到:
> (function(o){for(var i in o) console.log(i)})(this); ArrayBuffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array DataView global …… TypedArray相關物件 Global物件的別名,就像瀏覽器環境中的window物件
97.
開發NodeJS程式Global Scope環境 結果可以看到:
… process GLOBAL root Buffer setTimeout setInterval clearTimeout clearInterval console 處理行程的物件,有行程相關資訊、取得工作目錄等功能 Global物件的別名,就像瀏覽器環境中的window物件 用來處理binary資料的物件 跟瀏覽器中的一樣啦 用來做stdio的物件,可以輸出錯誤、debug、log等資訊
98.
開發NodeJS程式Global Scope環境 還漏掉一些(不會列舉出來):
… __dirname __pathname exports module 程式所在目錄的絕對路徑 所執行js檔案的絕對路徑 撰寫模組時,用來將介面輸出到呼叫端的物件 其實就是module.exports 提供目前模組的功能介面與資訊 如果撰寫「模組」,這幾個顯示的都是模組「local」的資訊
99.
開發NodeJS程式核心模組 核心模組是編譯在NodeJS執行檔中的模組 與外部模組一樣,透過下面方式載入使用
var http = require(‘http’);//將http模組載入,指派給http變數 var server = http.createServer(function(request, response) { //分析request資訊,寫入response }); server.listen(80, ‘127.0.0.1’);
100.
101.
重要的功能:
102.
console.log()/console.info(): 輸出訊息到標準輸出
103.
console.warn()/console.error(): 輸出訊息到標準錯誤
104.
console.dir(物件): 把物件資訊輸出到標準錯誤
105.
console.trace(): 傾印程式當前位置的stack trace資訊
106.
107.
重要的功能(跟瀏覽器中的一樣)
108.
setTimeout(callback, time)
109.
clearTimeout(tid)
110.
setInterval(callback, time)
111.
112.
重要的功能
113.
process.stdout / stderr:
寫入標準輸出/標準錯誤的writeable stream物件
114.
process.stdin: 讀取標準輸入的readable stream物件
115.
process.argv: 程式啟動時傳入的參數
116.
process.env: 取得系統環境變數
117.
process.nextTick(callback): 讓callback非同步執行
118.
process.cwd() / chdir():
取得/修改目前工作目錄
119.
120.
重要的功能
121.
util.format(): 返回格式化字串
122.
util.debug(string): 輸出訊息到標準錯誤,執行時會停止所有程式
123.
util.log(string): 輸出訊息到標準輸出,並加上時間資訊
124.
util.inspect(object): 回傳物件的代表資訊
125.
util.pump(readableStream, writeableStream): 將讀入直接轉到寫出
126.
127.
重要的功能
128.
emitter.on(‘event’, listener): 指定事件處理函數給特定事件
129.
emitter.once(): 同上,但是函數只會執行一次
130.
emitter.removeListener(‘evnet’, listener): 移除事件處理函數
131.
emitter.removeAllListeners(‘evnet’): 移除指定事件的所有處理函數
132.
emitter.listeners(‘event’): 返回指定事件的處理函數陣列
133.
134.
重要的功能
135.
new Buffer(): 建構子
136.
buffer.write(): 將字串寫入Buffer
137.
buffer.copy(): 把buffer的資料拷貝給指定的buffer物件
138.
buffer.length: 取得buffer的長度
139.
140.
重要的功能
141.
Readable Stream
142.
‘data’ 事件: 會在資料到達時觸發
143.
pipe(dest, [opt]): 可以把輸入(Readable)轉向輸出(Writeable)
144.
Writeable Stream
145.
write(buffer)/write(string, encoding): 將資料寫入
146.
147.
重要的功能
148.
createCredentials()/createHmac()/creatCipher()/createDecipher()/ createSign()/createVerify()/createDiffeHellman()等: 產生各種用來做加解密、hash、簽章、驗證等物件
149.
150.
重要的功能
151.
fs.open(path, flag, mode,
callback): 開啟檔案,fd會在開啟檔案後傳遞給callback
152.
fs.read(fd, buffer, offset,
length, position, [callback]): 讀取檔案
153.
fs.write(fd, buffer, offset,
length, position, [callback]): 寫入檔案
154.
fs.readFile(filename, [encoding], [callback]):
一次讀取整個檔案
155.
fs.close(fd): 關閉檔案
156.
157.
重要的功能
158.
net.createServer([opt], connectionListener): 產生net.Server物件,並且把connectionListener設定為’connection’事件處理函數,將net.Socket物件傳給它
159.
160.
重要的功能
161.
net.Server
162.
server.listen(): 監聽port或是fd
163.
server.close(): 關閉網路連接
164.
server.pause(): 暫停
165.
166.
重要的功能
167.
net.Socket
168.
connect事件:在socket連結建立時觸發
169.
data事件: 在socket收到資料時觸發
170.
connect(port or fd):
建立網路port或fd與socket的繫結
171.
setEncoding(encoding): 指定資料編碼格式ex. utf8,
ascii, base64
172.
write(data): 將資料寫入socket送出
173.
address(): 取得本地監聽的ip及port資料
174.
175.
使用說明
176.
客戶端每次建立一個連線,就會觸發connection事件
177.
透過傳遞給connection事件處理函數的net.Socket物件,就可以接收資料/傳遞資料
178.
179.
使用說明
180.
http.createServer(requestListener): 通常只要使用這個方法
181.
182.
使用說明
183.
ServerRequest
184.
request.url: 使用者request的網址
185.
request.method: http method,例如GET,
POST等
186.
request.headers: request header陣列
187.
188.
使用說明
189.
ServerResponse
190.
writeHead(status, [reasonPhrase], [headers]):
將http狀態及header回覆給client
191.
write(chuck, encoding): 將部份資料回覆給client
192.
193.
使用說明
194.
195.
使用說明
196.
vm.runInThisContext(code, [filename]): 在目前的context中編譯執行code字串,如果指定了filename,會調整process中的資訊(script檔名等)
197.
198.
使用說明(用不同方式執行可執行的程式,並取得其stdio)
199.
child_process.spawn()
200.
child_process.exec()
201.
202.
簡單的範例驗證概念 嘗試讓http server對應到檔案系統
構想 從最簡單的http server範例開始 利用fs模組讀取檔案內容 輸出到server response 範例:myweb-v0.0.1.js
203.
簡單的範例為模組化做準備 調整程式,把需要的操作用物件包裝,然後用建構函數來產生物件 只要把這個建構函數expose,就可以使用
如果需要單元測試,模組化會比較方便 範例:myweb-v0.0.2.js
204.
簡單的範例加上mime功能 server response需要提供mime
type,瀏覽器才有辦法知道怎樣使用 利用已經有人建構好的mime模組 範例:myweb-v0.0.3.js
205.
簡單的範例提供預設檔案功能 構想:如果request的資源是目錄,則在目錄中尋找index.html檔案,輸出到server response
範例:myweb-v0.0.4.js
206.
簡單的範例模組化 構想: 利用module.exports輸出MyHttpServer建構函數
使用時透過new 來建立實體 範例:myweb-v0.0.5.js, test-v0.0.5.js
207.
簡單的範例嘗試使用process.nextTick改進效能 構想: 一些流程利用匿名函數包裝,丟給process.nextTick非同步執行
不過實測對於效能並沒有明顯改進 範例:myweb-v0.0.6.js, test-v0.0.6.js
208.
209.
測試過,對於效能有明顯提昇範例:myweb-v0.0.7.js, test-v0.0.7.js
210.
簡單的範例加上router機制,讓網址對應到處理函數 構想: 模仿express
framework,利用get(‘path’, func)來新增利用GET方法,請求path路徑的處理函數func post, put, delete, head等也可以使用同樣方法 範例:myweb-v0.0.8.js, test-v0.0.8.js
211.
212.
利用nodeunit做單元測試,以確保架構調整沒有問題
213.
加上’init’ hook,並且在這個階段處理cookie
214.
hook函數,會接收到request與response物件做處理範例:myweb-v0.0.9.js, test-v0.0.9.js
215.
Windows環境? 目前的支援狀況還有與iis整合的方式
216.
217.
支援使用Visual C++編譯
218.
支援Named Pipe(類似Unix Domain
Socket)
219.
支援child process
220.
支援動態的原生模組 (dll格式)
221.
編譯成64位元執行檔
222.
223.
不需調整,就可以用VC++編譯,之前版本不行
224.
持續改進child process支援(完整支援據說還要一兩個月)
225.
226.
Q & A
227.
一些資源 http://nodejs.org http://npmjs.org
http://howtonode.org http://groups.google.com/group/nodejs http://www.facebook.com/NodeJS.tw http://wiki.nodejs.tw https://github.com/tjanczuk/iisnode
Descargar ahora