devcamp nodejs-2010

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

Upload: antono-vasiljev

Post on 18-Dec-2014

1.277 views

Category:

Technology


0 download

DESCRIPTION

Доклад о Node.js на Devcamp.by

TRANSCRIPT

Page 1: Devcamp nodejs-2010

Node.jsВозможности и перспективы

Antono Vasiljevhttp://antono.info/http://github.com/antono/http://groups.google.com/group/ru-nodejs/

Page 2: Devcamp nodejs-2010

Краткая история всего

¥Chromium (Сентябрь 2008)

¥СommonJS (Январь 2009)

¥Node.js (Февраль 2009)

Page 3: Devcamp nodejs-2010

Задача Node.js:

To provide a purely evented,non-blocking infrastructure toscript highly concurrent programs.

http://nodejs.org/

Page 4: Devcamp nodejs-2010

System Threads vs Single Thread

Page 5: Devcamp nodejs-2010

Apache

Page 6: Devcamp nodejs-2010
Page 7: Devcamp nodejs-2010

Node.js

Page 8: Devcamp nodejs-2010

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

Page 9: Devcamp nodejs-2010

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

интерфейс Stream

Page 10: Devcamp nodejs-2010

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

Page 11: Devcamp nodejs-2010

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

Page 12: Devcamp nodejs-2010

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

Page 13: Devcamp nodejs-2010

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

Page 14: Devcamp nodejs-2010

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); });});

Page 15: Devcamp nodejs-2010

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

Page 16: Devcamp nodejs-2010

Повторное исползованиекода на клиенте

http://requirejs.org

Page 17: Devcamp nodejs-2010

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

Page 18: Devcamp nodejs-2010

PostgreSQLMySQLRedis

MongoDBCouchDB

Sqilte

Page 19: Devcamp nodejs-2010

CucumberSeleniumJasmineJSpecVovs

Page 20: Devcamp nodejs-2010

ExpressPinturaGeddy

Page 21: Devcamp nodejs-2010

Socket.io и Nordstreamvar http = require('http'), io = require('socket.io')

server = http.createServer(function(req, res){ res.writeHeader(200, {'Content-Type': 'text/html'}); res.writeBody('<h1>Hello world</h1>'); 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(){ … }) });

Page 22: Devcamp nodejs-2010

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

Page 23: Devcamp nodejs-2010

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

Page 24: Devcamp nodejs-2010
Page 25: Devcamp nodejs-2010

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

Page 26: Devcamp nodejs-2010

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