0
node.js dao Vova Miguro
What’s it all about?
<ul><li>Node.js  is a platform built on  Chrome’s JavaScript   runtime  for easily building fast, scalable network applica...
How? <ul><li>Let’s keep slow operations from blocking other operations. </li></ul>
traditional I/O var  data = file.read( ‘image.png’ ); //zzz... doSomething(data); something not right here...
async I/O file.read( ‘image.png’ , function (data){ doSomething(image); }); doSomethingElse(); profit!
callback() callback() callback()
node.js internals <ul><li>v8  (yeah, it’s Chrome’s engine) </li></ul><ul><li>libev  (event loop) </li></ul><ul><li>libeio ...
it is only one thread! <ul><li>file.read( ‘file.txt’ , function (data){ </li></ul><ul><ul><li>//will never fire... </li></...
http server var  http = require( 'http' ); http.createServer( function  (req, res) { res.writeHead( 200 , { 'Content-Type'...
watch file var  fs = require( 'fs' ); fs.watchFile( 'system.log' , function  () { console.log( 'log changed!' ); });
 
node & mongo var  mongodb = require( 'mongodb' ); var  server =  new  Server( '127.0.0.1' ,  27017 , {}); new  Db( 'test' ...
node & web sockets //server var  io = require( 'socket.io' ).listen( 80 ); io.sockets.on( 'connection' ,  function  (socke...
let’s see...
suited for... <ul><li>real time </li></ul><ul><li>streaming </li></ul><ul><li>process monitoring </li></ul><ul><li>JSON AP...
do not use for this... <ul><li>CPU heavy apps </li></ul><ul><li>data transformation </li></ul>
?
Upcoming SlideShare
Loading in...5
×

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

1,690

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,690
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Владимир Мигуро "Дао 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 Worldn' ); }).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. ?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×