Slide 1

Slide 1 text

Node.js Возможности и перспективы Antono Vasiljev http://antono.info/ http://github.com/antono/ http://groups.google.com/group/ru-nodejs/

Slide 2

Slide 2 text

Краткая история всего ¥Chromium (Сентябрь 2008) ¥СommonJS (Январь 2009) ¥Node.js (Февраль 2009)

Slide 3

Slide 3 text

Задача Node.js: To provide a purely evented, non-blocking infrastructure to script highly concurrent programs. http://nodejs.org/

Slide 4

Slide 4 text

System Threads vs Single Thread

Slide 5

Slide 5 text

Apache

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Node.js

Slide 8

Slide 8 text

Событийная, асинхронная модель обработки данных

Slide 9

Slide 9 text

Операции ввода-вывода унифицированы реализуют интерфейс Stream

Slide 10

Slide 10 text

Объекты выполняющие I/O регистрируют обработчики событий

Slide 11

Slide 11 text

И вызывают их...

Slide 12

Slide 12 text

$.get('ajax/test.html', function(data) { $('.result').html(data); alert('Load was performed.'); });

Slide 13

Slide 13 text

$.ajax({ url: 'ajax/test.html', success: function(data) { $('.result').html(data); alert('Load was performed.'); }, error: function() {}, complete: function() {}, beforeSend: function() {} });

Slide 14

Slide 14 text

var http = require('http'); var google = http.createClient(80, 'www.google.com'); var request = google.request('GET', '/', {'host': 'www.google.com'}); request.end(); request.on('response', function (response) { console.log('STATUS: ' + response.statusCode); console.log('HEADERS: ' + JSON.stringify(response.headers)); response.setEncoding('utf8'); response.on('data', function (chunk) { console.log('BODY: ' + chunk); }); });

Slide 15

Slide 15 text

JavaScript на сервере Наше все ;)

Slide 16

Slide 16 text

Повторное исползование кода на клиенте http://requirejs.org

Slide 17

Slide 17 text

Что уже готово?

Slide 18

Slide 18 text

PostgreSQL MySQL Redis MongoDB CouchDB Sqilte

Slide 19

Slide 19 text

Cucumber Selenium Jasmine JSpec Vovs

Slide 20

Slide 20 text

Express Pintura Geddy

Slide 21

Slide 21 text

Socket.io и Nordstream var http = require('http'), io = require('socket.io') server = http.createServer(function(req, res){ res.writeHeader(200, {'Content-Type': 'text/html'}); res.writeBody('

Hello world

'); res.finish(); }); // socket.io var socket = io.listen(server); socket.on('connection', function(client){ // new client is here! client.on('message', function(){ … }) client.on('disconnect', function(){ … }) });

Slide 22

Slide 22 text

var socket = new io.Socket(); socket.on('connect', function(){ socket.send('hi!'); }) socket.on('message', function(data){ alert(data); }) socket.on('disconnect', function(){})

Slide 23

Slide 23 text

Nordstream var connections = 0; var nodestream = io.listen(app).nodestream() .on('connect', function(){ connections++; this.emit('connections', connections); }) .on('disconnect', function(){ connections--; this.emit('connections', connections); }); :realtime(repaint: 'connections', local: 'connections') .connections - if (connections > 1) p #{connections} people are editing right now - else p You're all alone, loser

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Сообщество http://nodejs.ru/ http://groups.google.com/group/ru-nodejs/ http://groups.google.com/group/nodejs/

Slide 26

Slide 26 text

http://nodejs.org/ http://howtonode.org/ http://antono.info/