Node.js ´» ½°‡¸½°‰¸…

  • View
    1.767

  • Download
    12

Embed Size (px)

DESCRIPTION

 

Text of Node.js ´» ½°‡¸½°‰¸…

  • 1. http://serenity.su, 29 12.

2. http://serenity.su : 12 Serenity HTML5/JavaScript simonenko.su github.com/meritt, 29 12. 3. http://serenity.suNODE.JS 3, 29 12. 4. http://serenity.su : Windows, OS X, Linux 1 http://nodejs.org/#download, 29 12. 5. http://serenity.su NODE.JS? JavaScript Google Chrome V85, 29 12. 6. http://serenity.su NODE.JS? JavaScript Google Chrome V8 Event-driven, non-blocking I/O, streams5, 29 12. 7. http://serenity.su NODE.JS? JavaScript Google Chrome V8 Event-driven, non-blocking I/O, streams (HTTP, DNS, TLS/SSL)5, 29 12. 8. http://serenity.su NODE.JS? JavaScript Google Chrome V8 Event-driven, non-blocking I/O, streams (HTTP, DNS, TLS/SSL) NodePackage Manager (npm) 9000 5, 29 12. 9. http://serenity.su HELLO WORLDvar http = require(http);var server = http.createServer(function(request, response) {response.writeHead(200, {Content-Type: text/plain});response.end(Hello World);});server.listen(3000);console.log(Server running at http://127.0.0.1:3000);, 29 12. 10. http://serenity.su $ node server.jsServer running at http://127.0.0.1:3000 7, 29 12. 11. http://serenity.su NODE.JS PHP digitalconf.ru htmlacademy.ru $ ab -c 10 -n 1000 http://digitalconf.ru/ node.js : nginx, nodejs, express php : apache, php, zend framework 8, 29 12. 12. http://serenity.su ab -c 10 -n 1000digitalconf.ru203htmlacademy.ru 25 055 110165 220Requests per second9, 29 12. 13. http://serenity.su !?, 29 12. 14. http://serenity.su I/O, 29 12. 15. http://serenity.su I/O, 29 12. 16. http://serenity.su I/O, 29 12. 17. http://serenity.su , ., 29 12. 18. http://serenity.su I/O, 29 12. 19. http://serenity.su NODE.JS CPU , 29 12. 20. http://serenity.suCOMMONJS , 29 12. 21. http://serenity.su // hello.jsexports.world = function(text) { return Hello+ text + !;};// server.jsvar http = require(http);var hello = require(./hello);var server = http.createServer(function(request, response) {response.writeHead(200, {Content-Type: text/plain});response.end(hello.world(ITMO));});server.listen(3000);console.log(Server running at http://127.0.0.1:3000);, 29 12. 22. http://serenity.su $ node server.jsServer running at http://127.0.0.1:3000 19, 29 12. 23. http://serenity.su NPMNODE PACKAGE MANAGER, 29 12. 24. http://serenity.su express sinatra inspired web development framework mustache logic-less {{mustache}} templates with JavaScript socket.io real-time apps made cross-browser & easy with a WebSocket-like API request simplied HTTP request client async higher-order functions and common patterns for asynchronous code, 29 12. 25. http://serenity.su ?$ npm install expressexpress@2.5.9 ./node_modules/express!"" qs@0.4.2!"" mime@1.2.4!"" mkdirp@0.3.0#"" connect@1.8.7 (formidable@1.0.9), 29 12. 26. http://serenity.su HELLO WORLD EXPRESSvar express = require(express);var server = express.createServer();server.get(/, function(request, response) {response.send(Hello Express World);});server.listen(3000);console.log(Server running at http://127.0.0.1:3000);, 29 12. 27. http://serenity.su $ node server.jsServer running at http://127.0.0.1:3000 24, 29 12. 28. http://serenity.su , 29 12. 29. http://serenity.su var express = require(express); var server = express.createServer(); server.get(/, function(request, response) { response.redirect(/alexey); }); server.get(/:name, function(request, response) { response.send(Hello+ request.params.name + !); }); server.listen(3000); console.log(Server running at http://127.0.0.1:3000);, 29 12. 30. http://serenity.su $ node server.jsServer running at http://127.0.0.1:3000 27, 29 12. 31. http://serenity.su , 29 12. 32. http://serenity.su var animals = {cats: 10, dogs: 1, frogs: 6, turtles: 17};for (animal in animals) {setTimeout(function() {console.log(animal + :+ animals[animal]);}, 100);}, 29 12. 33. http://serenity.su var animals = {cats: 10, dogs: 1, frogs: 6, turtles: 17};for (animal in animals) {setTimeout(function() { $ node example.jsconsole.log(animal + :+ animals[animal]);}, 100); turtles: 17}turtles: 17turtles: 17turtles: 17, 29 12. 34. http://serenity.su var animals = {cats: 10, dogs: 1, frogs: 6, turtles: 17};bad wayfor (animal in animals) {setTimeout(function() { $ node example.jsconsole.log(animal + :+ animals[animal]);}, 100); turtles: 17}turtles: 17turtles: 17turtles: 17, 29 12. 35. http://serenity.su var animals = {cats: 10, dogs: 1, frogs: 6, turtles: 17};for (animal in animals) {(function(animal) {setTimeout(function() {console.log(animal + :+ animals[animal]);}, 100);})(animal);}, 29 12. 36. http://serenity.su var animals = {cats: 10, dogs: 1, frogs: 6, turtles: 17};for (animal in animals) {(function(animal) {setTimeout(function() {$ node example.js cats: 10console.log(animal + :+ animals[animal]);}, 100); dogs: 1})(animal);frogs: 6}turtles: 17, 29 12. 37. http://serenity.su var animals = {cats: 10, dogs: 1, frogs: 6, turtles: 17}; good wayfor (animal in animals) {(function(animal) {setTimeout(function() {$ node example.js cats: 10console.log(animal + :+ animals[animal]);}, 100); dogs: 1})(animal);frogs: 6}turtles: 17, 29 12. 38. http://serenity.suvar fs = require(fs);function content() {var results = [];var files = [1, 2, 3, 4, 5];for (var i=0; i