Let s Enjoy Node.js

8,100 views

Published on

The next generation JavaScript doesn't need to dependent on browser, that's just like other programming language. Node.js is it, no need browser, based on fastest V8 JavaScript Engine and provides many APIs for system integration. It can be used to server-side and system, even more purpose.

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,100
On SlideShare
0
From Embeds
0
Number of Embeds
5,520
Actions
Shares
0
Downloads
78
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Let s Enjoy Node.js

  1. 1. Lets Enjoy Node.js All in JavaScript Fred Chien
  2. 2. Enjoy Trip With 2 Rules 旅程將啟,兩點規則
  3. 3. 1Buckle Up! 請繫安全帶!
  4. 4. 2DO NOT KICK MY ASS! 請你的朋友不要打我的頭!
  5. 5. 說好不打臉的! 說好喔!
  6. 6. WHO AM I ? 我是誰?
  7. 7. Fred Chien 錢逢祥 永遠的大四生
  8. 8. Fred Chien 錢逢祥 永遠的大四生
  9. 9. Fred Chien 錢逢祥宅宅水電工
  10. 10. 慾火焚身的男人
  11. 11. fred-zone.blogspot.com cfsghost @ gmail.com
  12. 12. JavaScript 大調查
  13. 13. Web 開發者共同的迷思 底層難!Porting 難!神人!大牛!
  14. 14. 共同的夢想JavaScript 成為海賊王!!!
  15. 15. JavaScriptIs NOT Browser-side Language Anymore 是否不再只是瀏覽器端語言?
  16. 16. 橡膠果實使一切成為可能
  17. 17. Run JavaScript without Browser 不需要瀏覽器的 JavaScript
  18. 18. Old School JavaScript
  19. 19. Without Browser
  20. 20. With Node.js
  21. 21. More Third-party Modules
  22. 22. More Supports
  23. 23. 換句話說In other words
  24. 24. Enjoy JavaScript Enjoy It
  25. 25. Server-side Development 開發後端應用
  26. 26. PHP/Perl/Python/JSP/ASP... 開發後端應用
  27. 27. System Development 開發系統程式
  28. 28. Services/Daemon/Syscall...etc 控制作業系統的一切
  29. 29. 更進一步 Even More
  30. 30. All Development 開發一切應用
  31. 31. About node.js● Stable version is 0.6.15● Support platforms: ○ MS Windows ○ Mac OS X ○ Linux ○ FreeBSD
  32. 32. node.js Features● Based on V8 JavaScript Engine (With JIT)● Stand-alone (Without Web Browser)● Event-driven● Non-blocking I/O model
  33. 33. More Good Things Come● Extending with C/C++● Support Multi-core Systems● Provide Buffer Class ○ Solve 1.9GB heap limit of V8 ○ Nice to binary data
  34. 34. Great Performance on Server● Thousands of Concurrent Connections● Minimal Overhead (CPU/Memory) on a singal process
  35. 35. Hello World 快速試看看
  36. 36. Hello World! (helloworld.js)var http = require(http);http.createServer(function(req, res) { res.writeHead(200, {Content-Type: text/plain}); res.end(Hello Worldn);}).listen(10000);console.log(Server running at http://localhost:10000/);
  37. 37. Run It!$ node ./helloworld.jsServer running at http://localhost:10000/
  38. 38. Cluster Support (cluster.js)var cluster = require(cluster);var http = require(http);var numCPUs = require(os).cpus().length;if (cluster.isMaster) { // Fork workers. for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on(death, function(worker) { console.log(worker + worker.pid + died); });} else { // Worker processes have a http server. http.Server(function(req, res) { res.writeHead(200); res.end("hello worldn"); }).listen(8000);}
  39. 39. Run It!$ node ./cluster.jsWorker 18394 onlineWorker 18393 online
  40. 40. MongoDB Support (mongodb.js)var mongodb = require(mongodb);var server = new mongodb.Server(localhost, 27017);var db = new mongodb.Db(mydb, server);/* open db */db.open(function() { /* Select contact collection */ db.collection(contact, function(err, collection) { /* Querying (name == Fred Chien) */ collection.find({ name: Fred Chien }, function(err, data) { console.log(Name: + data.name + , email: + data.email); }); });});
  41. 41. Run It!$ node ./mongodb.jsname: Fred Chien, email: cfsghost@gmail.com
  42. 42. Write a XMPP Server (xmppsrv.js)var xmpp = require(node-xmpp);var c2s = new xmpp.C2S({ port: 5222, domain: example.com});c2s.on("authenticate", function(jid, password, client) { if (password == "12345678") { client.emit("auth-success", jid); } else { client.emit("auth-fail", jid); }});console.log(My XMPP Server was running at localhost:5222);
  43. 43. Run It!$ node ./xmppsrv.jsMy XMPP Server was running at localhost:5222
  44. 44. Node.js Modules 你可以抓到更多的模組
  45. 45. NPMNode Package Manager
  46. 46. 8844+Large Amount of Module
  47. 47. Get Modules with NPM$ npm install mongodb$ npm install node-xmpp
  48. 48. References● Node.js Official Website: http://nodejs.org/● NPM Official Website: http://npmjs.org/
  49. 49. Community in Taiwan ● Node.js Taiwan http://nodejs.tw/ ● Facebook Fans Page # NodeJS.tw ● Node.js Taiwan Party in Taipei Once Every other Thursday
  50. 50. 總結來說... Anyway...
  51. 51. 前端開發者走入後端 一種語言前後都可玩
  52. 52. Web開發者將實現夢想寫系統程式啦
  53. 53. 低階程式讓專業的來用 Node.js C/C++ Addon 打通硬體和系統的任督二脈
  54. 54. JSer 只要專心惡搞 仍然不需要管底層的事
  55. 55. 大秘寶就是我們的! 我是海賊王!
  56. 56. Question? 提問?
  57. 57. Thanks感謝您的耐心耹聽

×