devcamp nodejs-2010
DESCRIPTION
Доклад о Node.js на Devcamp.byTRANSCRIPT
Node.jsВозможности и перспективы
Antono Vasiljevhttp://antono.info/http://github.com/antono/http://groups.google.com/group/ru-nodejs/
Краткая история всего
¥Chromium (Сентябрь 2008)
¥СommonJS (Январь 2009)
¥Node.js (Февраль 2009)
Задача Node.js:
To provide a purely evented,non-blocking infrastructure toscript highly concurrent programs.
http://nodejs.org/
System Threads vs Single Thread
Apache
Node.js
Событийная, асинхронная модельобработки данных
Операции ввода-вывода унифицированы реализуют
интерфейс Stream
Объекты выполняющие I/O регистрируют обработчики событий
И вызывают их...
$.get('ajax/test.html', function(data) { $('.result').html(data); alert('Load was performed.');});
$.ajax({ url: 'ajax/test.html', success: function(data) { $('.result').html(data); alert('Load was performed.'); }, error: function() {}, complete: function() {}, beforeSend: function() {}});
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); });});
JavaScript на сервереНаше все ;)
Повторное исползованиекода на клиенте
http://requirejs.org
Что уже готово?
PostgreSQLMySQLRedis
MongoDBCouchDB
Sqilte
CucumberSeleniumJasmineJSpecVovs
ExpressPinturaGeddy
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(){ … }) });
var socket = new io.Socket(); socket.on('connect', function(){ socket.send('hi!'); }) socket.on('message', function(data){ alert(data); })socket.on('disconnect', function(){})
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
Сообществоhttp://nodejs.ru/http://groups.google.com/group/ru-nodejs/http://groups.google.com/group/nodejs/
http://nodejs.org/http://howtonode.org/http://antono.info/