Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
Próximo SlideShare
Ch2.setup.node.and.npm
Ch2.setup.node.and.npm
Cargando en…3
×
1 de 17

Node Web Development 2nd Edition: Chapter1 About Node

0

Compartir

Descargar para leer sin conexión

Node Web Development 2nd Edition: Chapter1 About Node

Libros relacionados

Gratis con una prueba de 30 días de Scribd

Ver todo

Audiolibros relacionados

Gratis con una prueba de 30 días de Scribd

Ver todo

Node Web Development 2nd Edition: Chapter1 About Node

  1. 1. About Node Rick Chang
  2. 2. What is Node A Platform to write JavasScript applications outside web browsers. No DOM No bowser capability Act as a web server Care about HTTP headers
  3. 3. About Node No thread (run single-threaded) Event-driven architecture (publish/subscribe) Google V8 JavaScript engine Non-block I/O event loop (Asynchronous I/O) File and network I/O libraries (use multiple threads)
  4. 4. History Ryan Dahl created in 2009[1] chose JavaScript because of the lack of an existing I/O API Build high performance and scalable network applications Sponsored by Joyent[2] Inspired By seeing a file upload progress bar on Flickr npm created by Isaac Schlueter, a package manager was introduced in 2011 Microsoft partnered to create a native Windows version in July 2011
  5. 5. Server-side JavaScript RingoJS (http://ringojs.org/) Based on Mozilla Rhino and written in Java Node Based on Google V8
  6. 6. JavasScript loosely typed dynamically extendable objects anonymous closures
  7. 7. Pub/Sub Pattern pub.sub.js Result foo 1 2 foo.bar 1 2 foo.baz 1 2 ! foo.bar 3 4 ! foo.baz 5 6 ! foo 7 8 foo.baz 7 8
  8. 8. Extend Object Dynamically people.js The employee works hard Drive vehicle Result
  9. 9. JavaScript vs Java Java Non-dynamic language Static typed The compiler catch programming mistakes JavaScript Dynamic language Loosely typed Global Object Global Object cause an unruly chaos!!
  10. 10. Node.js CommonJS module system Make variables local to a module Demo code
  11. 11. Demo parent.js example.js
  12. 12. Asynchronous I/O A single-thread event loop without thread context switch Callback function to handle result result = query('SELECT * from db'); // operate on the result query('SELECT * from db', function (err, result) { if (err) throw err; // handle errors // operate on result });
  13. 13. Benchmark var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Node Nginx Throughput 822 req/sec 704 req/sec Memory Used 64M 4M
  14. 14. Company Yahoo! LinkedIn Replace Ruby on Rails to Node Paypal
  15. 15. Conclusion Node is a great platform for I/O-bound applications No good for computationally expensive calculations Finbonacci sequence calcuation More performance, fewer servers, lower cost and lower environment impact
  16. 16. Debate Node.js favours performance over usability and robustness Difficult to debug, refactor and develop no synchronous code duplicate callback emitters may get multiple “error” events missing “error” events sends everything to hell “error” handlers are very verbose
  17. 17. Reference [1]Node.js, http://en.wikipedia.org/wiki/Node.js [2]Joyent, https://www.joyent.com/ [3]Farewell Node.js, TJ Holowaychuk, https://medium.com/code- adventures/farewell-node-js-4ba9e7f3e52b [4]关于TJ⼤大神的Farewell Node.js, http://www.welefen.com/about-tj- farewell-node.js-article.html [5]JavaScript模块化开发(⼆二)—CommonJS规范, http:// www.feeldesignstudio.com/2013/09/javascript-module-pattern-commonjs [6]CommonJS规范, http://javascript.ruanyifeng.com/nodejs/ commonjs.html

×