Successfully reported this slideshow.
Your SlideShare is downloading. ×

Владимир Мигуро "Дао Node.js"

Ad

node.js dao Vova Miguro

Ad

What’s it all about?

Ad

<ul><li>Node.js  is a platform built on  Chrome’s JavaScript   runtime  for easily building fast, scalable network applica...

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Upcoming SlideShare
Jk rubyslava 25
Jk rubyslava 25
Loading in …3
×

Check these out next

1 of 18 Ad
1 of 18 Ad
Advertisement

More Related Content

Advertisement

More from EPAM Systems (20)

Advertisement

Владимир Мигуро "Дао Node.js"

  1. 1. node.js dao Vova Miguro
  2. 2. What’s it all about?
  3. 3. <ul><li>Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. </li></ul><ul><li>-nodejs.org </li></ul>
  4. 4. How? <ul><li>Let’s keep slow operations from blocking other operations. </li></ul>
  5. 5. traditional I/O var data = file.read( ‘image.png’ ); //zzz... doSomething(data); something not right here...
  6. 6. async I/O file.read( ‘image.png’ , function (data){ doSomething(image); }); doSomethingElse(); profit!
  7. 7. callback() callback() callback()
  8. 8. node.js internals <ul><li>v8 (yeah, it’s Chrome’s engine) </li></ul><ul><li>libev (event loop) </li></ul><ul><li>libeio (asynchronous version of POSIX API) </li></ul>
  9. 9. it is only one thread! <ul><li>file.read( ‘file.txt’ , function (data){ </li></ul><ul><ul><li>//will never fire... </li></ul></ul><ul><li>}) </li></ul><ul><li>while ( true ){ </li></ul><ul><ul><li>//blocking entire process </li></ul></ul><ul><li>} </li></ul>
  10. 10. http server var http = require( 'http' ); http.createServer( function (req, res) { res.writeHead( 200 , { 'Content-Type' : 'text/plain' }); res.end( 'Hello World' ); }).listen( 3000 );
  11. 11. watch file var fs = require( 'fs' ); fs.watchFile( 'system.log' , function () { console.log( 'log changed!' ); });
  12. 13. node & mongo var mongodb = require( 'mongodb' ); var server = new Server( '127.0.0.1' , 27017 , {}); new Db( 'test' , server, {}).open( function (error, client) { var collection = new Collection(client, 'tmp' ); //insert doc collection.insert({a: 12 ,b: 'string' },{},function(){ //find doc collection.find({}, {limit: 10 }).toArray( function (err, docs) { //do smth with docs }); }); });
  13. 14. node & web sockets //server var io = require( 'socket.io' ).listen( 80 ); io.sockets.on( 'connection' , function (socket) { socket.emit( 'news' , {hello: 'world' }); }); //client var socket = io.connect( ' http://localhost ' ); socket.on( 'news' , function (data) { console.log(data); });
  14. 15. let’s see...
  15. 16. suited for... <ul><li>real time </li></ul><ul><li>streaming </li></ul><ul><li>process monitoring </li></ul><ul><li>JSON API’s </li></ul>
  16. 17. do not use for this... <ul><li>CPU heavy apps </li></ul><ul><li>data transformation </li></ul>
  17. 18. ?

×