Node.js 1, 2, 3Knowing the usage of Node.jsSimple web server for example    Zack Pan / StarNight
目錄 1. 參考資料 2. 前人智慧的啟發 3. 安裝Node.js 4. 用 ...
參考資料Manuel Kiessling, Node入門http://www.nodebeginner.org/index-zh-tw.htmlNode.js Official Sitehttp://nodejs.org/本slide可以說是N...
前人智慧的啟發Web Server    Apache, lighttpd, Nginx ...Functions (Apache for example)    virtual hosts, proxy, CGI ...CGI / FastC...
Apache Httpd       是我最熟悉的Web Server     它有很多功能,沒有做不到的事           所以它很肥大    縮減功能,拿掉不必要的,可以更快      As Simple As Better!!!
我想要極致效能1. Apache掛Fast-cgi → PHP快 Python快 ...2. Apache掛CGI → Binary program3. Jserv, 以 GDB 重新學習 C 語言程式設計  http://blog.linux...
慣C自幹Web Server                      要先喀完                 RFC2616 Hypertext Transfer Protocol -- HTTP/1.1      http://www.w...
直到有一天,我遇見Node.js這樣就是一個Web Server !!!var http = require("http");http.createServer(function(request, response) {    response...
Wiki Node.jsNode.js is a packaged compilation of GooglesV8 JavaScript engine.Node.js is a server-side software systemdesig...
安裝Node.js http://nodejs.org
Hello World!helloworld.js            debug message to STDOUT  console.log("Hello World!");node helloworld.js
一個Web Server要● 一個會HTTP 1.1的Web server● 看得懂URL● 要可以根據URL做不同的動作● 最起碼可以接GET和POST的資料● 可以根據Request,有相對應的HTTP Response給Client
一個簡單的Web Server by Node.jsvar http = require("http");       宣告要使用http模組                    建立一HTTP Serverhttp.createServer...
善用Node.js Docs   http://nodejs.org/api/
Require → #include in C               Core Modules                File ModulesLoading from node_modules Folders http://nod...
函數傳遞javascript function除了可以傳參數,也可以傳function,就跟C可以傳函式指標一樣 function say(word) {   console.log(word); } function execute(some...
Type of function object    Function 也是 Object  ECMAScript® Language Specification          Wiki function object           ...
http modulevar http = require("http");http.createServer(function(request, response) {    response.writeHead(200, {"Content...
匿名函式掛給request event執行var http = require("http");http.createServer(   function(request, response) {      response.writeHead...
Node.js的特性如同網頁瀏覽器一樣,在Node.js跑javascript的V8 JavaScript engine是single thread。程式碼原則是由上而下執行,因此可以寫順序式的程式。碰到I/O有關的程式,整個process就會...
Callback function for event-drivenvar http = require("http");                  定義Callback function for request eventfuncti...
Event in Node.js → Interrupt of chip      Is that right?????  Understanding the node.js         event loop
Arguments of the callback functionfunction onRequest(request, response) {  console.log("Request received.");  response.wri...
Module              將HTTP Server相關的code包裝var http = require("http");function onRequest(request, response) {  console.log("...
mylib.jsfunction foo(port) {  var http = require("http");  function onRequest(request, response) {     console.log("Reques...
server.jsvar server = require("./mylib");var linstening_port = 8888;server.onRequest(linstening_port);
Create NPM package      在專案根目錄加上package.json檔 詳細項目說明https://npmjs.org/doc/json.htmlExamples:  Create NPM Package – Node.js...
以上是Node.js基本認識其餘請繼續Node入門
Node.js還可以Java script 全面逆襲!使用   node.js 打造桌面環境!   Fred @ COSCUP 2012http://www.slideshare.net/cfsghost/java-script-nodejs
Upcoming SlideShare
Loading in...5
×

Node.js 1, 2, 3

1,171

Published on

Node.js introduction

Published in: Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,171
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Node.js 1, 2, 3

  1. 1. Node.js 1, 2, 3Knowing the usage of Node.jsSimple web server for example Zack Pan / StarNight
  2. 2. 目錄 1. 參考資料 2. 前人智慧的啟發 3. 安裝Node.js 4. 用 ...
  3. 3. 參考資料Manuel Kiessling, Node入門http://www.nodebeginner.org/index-zh-tw.htmlNode.js Official Sitehttp://nodejs.org/本slide可以說是Node入門的讀完心得
  4. 4. 前人智慧的啟發Web Server Apache, lighttpd, Nginx ...Functions (Apache for example) virtual hosts, proxy, CGI ...CGI / FastCGI CGI, Perl, PHP, Python, Ruby ...
  5. 5. Apache Httpd 是我最熟悉的Web Server 它有很多功能,沒有做不到的事 所以它很肥大 縮減功能,拿掉不必要的,可以更快 As Simple As Better!!!
  6. 6. 我想要極致效能1. Apache掛Fast-cgi → PHP快 Python快 ...2. Apache掛CGI → Binary program3. Jserv, 以 GDB 重新學習 C 語言程式設計 http://blog.linux.org.tw/~jserv/archives/2010/04/_gdb_c_1.html4. 自己用C刻一個有HTTP Server功能的程式
  7. 7. 慣C自幹Web Server 要先喀完 RFC2616 Hypertext Transfer Protocol -- HTTP/1.1 http://www.w3.org/Protocols/rfc2616/rfc2616.html 所以我就放棄這麼做了!
  8. 8. 直到有一天,我遇見Node.js這樣就是一個Web Server !!!var http = require("http");http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}).listen(8888);
  9. 9. Wiki Node.jsNode.js is a packaged compilation of GooglesV8 JavaScript engine.Node.js is a server-side software systemdesigned for writing scalable Internetapplications, notably web servers. Programsare written on the server side in JavaScript,using event-driven, asynchronous I/O tominimize overhead and maximize scalability.
  10. 10. 安裝Node.js http://nodejs.org
  11. 11. Hello World!helloworld.js debug message to STDOUT console.log("Hello World!");node helloworld.js
  12. 12. 一個Web Server要● 一個會HTTP 1.1的Web server● 看得懂URL● 要可以根據URL做不同的動作● 最起碼可以接GET和POST的資料● 可以根據Request,有相對應的HTTP Response給Client
  13. 13. 一個簡單的Web Server by Node.jsvar http = require("http"); 宣告要使用http模組 建立一HTTP Serverhttp.createServer( function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); Callback Function}).listen(8888); 要該HTTP Server監聽8888 port
  14. 14. 善用Node.js Docs http://nodejs.org/api/
  15. 15. Require → #include in C Core Modules File ModulesLoading from node_modules Folders http://nodejs.org/api/modules.html#modules_modules
  16. 16. 函數傳遞javascript function除了可以傳參數,也可以傳function,就跟C可以傳函式指標一樣 function say(word) { console.log(word); } function execute(someFunction, value) { someFunction(value); } execute(say, "Hello");
  17. 17. Type of function object Function 也是 Object ECMAScript® Language Specification Wiki function object Javascript typeof 認識 JavaScript 的物件導向技術
  18. 18. http modulevar http = require("http");http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}).listen(8888);http://nodejs.org/api/http.html#http_http_createserver_requestlistener
  19. 19. 匿名函式掛給request event執行var http = require("http");http.createServer( function(request, response) { response.writeHead( 200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8888);http://nodejs.org/api/http.html#http_event_request
  20. 20. Node.js的特性如同網頁瀏覽器一樣,在Node.js跑javascript的V8 JavaScript engine是single thread。程式碼原則是由上而下執行,因此可以寫順序式的程式。碰到I/O有關的程式,整個process就會被block住,直到I/O回應執行完畢,才會往下執行。與I/O有關的程式,要用event的概念來解決block問題。
  21. 21. Callback function for event-drivenvar http = require("http"); 定義Callback function for request eventfunction onRequest(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();} 將onRequest註冊至request eventhttp.createServer(onRequest).listen(8888);console.log("Server has started.");
  22. 22. Event in Node.js → Interrupt of chip Is that right????? Understanding the node.js event loop
  23. 23. Arguments of the callback functionfunction onRequest(request, response) { console.log("Request received."); response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end();}request: instance of http.IncomingMessageresponse: instance of http.ServerResponsehttp://nodejs.org/api/http.html#http_event_request
  24. 24. Module 將HTTP Server相關的code包裝var http = require("http");function onRequest(request, response) { console.log("Request received."); response.end("Hello World");}http.createServer(onRequest).listen(8888);console.log("Server has started.");
  25. 25. mylib.jsfunction foo(port) { var http = require("http"); function onRequest(request, response) { console.log("Request received."); response.end("Hello World"); } http.createServer(onRequest).listen(port); console.log("Server has started.");}exports.onRequest = foo;
  26. 26. server.jsvar server = require("./mylib");var linstening_port = 8888;server.onRequest(linstening_port);
  27. 27. Create NPM package 在專案根目錄加上package.json檔 詳細項目說明https://npmjs.org/doc/json.htmlExamples: Create NPM Package – Node.js Module NPM 套件管理工具如何在Node.js中使用npm创建和发布一个模块
  28. 28. 以上是Node.js基本認識其餘請繼續Node入門
  29. 29. Node.js還可以Java script 全面逆襲!使用 node.js 打造桌面環境! Fred @ COSCUP 2012http://www.slideshare.net/cfsghost/java-script-nodejs

×