0% found this document useful (0 votes)
194 views

Devcamp - by Node - Js 2010

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows JavaScript to be run on the server-side. Node.js provides a non-blocking I/O model that makes it very efficient for data-intensive real-time applications that run across distributed devices. Many popular frameworks and libraries like Express, Socket.io, and PostgreSQL already provide integration with Node.js. An active community has formed around Node.js to support its continued development.

Uploaded by

Antono Vasiljev
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views

Devcamp - by Node - Js 2010

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows JavaScript to be run on the server-side. Node.js provides a non-blocking I/O model that makes it very efficient for data-intensive real-time applications that run across distributed devices. Many popular frameworks and libraries like Express, Socket.io, and PostgreSQL already provide integration with Node.js. An active community has formed around Node.js to support its continued development.

Uploaded by

Antono Vasiljev
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Node.

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

Antono Vasiljev
http://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 to
script 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
Что уже готово?
PostgreSQL
MySQL
Redis
MongoDB
CouchDB
Sqilte
Cucumber
Selenium
Jasmine
JSpec
Vovs
Express
Pintura
Geddy
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('<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/

You might also like