Владимир Мигуро "Дао Node.js"
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

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

on

  • 2,129 views

 

Statistics

Views

Total Views
2,129
Views on SlideShare
1,952
Embed Views
177

Actions

Likes
1
Downloads
10
Comments
0

9 Embeds 177

http://evusprisd0119 95
http://info.epam.com 44
http://evbyminsa0090 13
http://evbyminsa0089 8
https://twitter.com 8
http://author.info.epam.com 4
http://dev.publish.info.epam.com 3
http://evusprisd0146 1
http://localhost 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • 1. node.js dao Vova Miguro
  • 2. What’s it all about?
  • 3.
    • Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications.
    • -nodejs.org
  • 4. How?
    • Let’s keep slow operations from blocking other operations.
  • 5. traditional I/O var data = file.read( ‘image.png’ ); //zzz... doSomething(data); something not right here...
  • 6. async I/O file.read( ‘image.png’ , function (data){ doSomething(image); }); doSomethingElse(); profit!
  • 7. callback() callback() callback()
  • 8. node.js internals
    • v8 (yeah, it’s Chrome’s engine)
    • libev (event loop)
    • libeio (asynchronous version of POSIX API)
  • 9. it is only one thread!
    • file.read( ‘file.txt’ , function (data){
      • //will never fire...
    • })
    • while ( true ){
      • //blocking entire process
    • }
  • 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. 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 }); }); });
  • 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); });
  • 15. let’s see...
  • 16. suited for...
    • real time
    • streaming
    • process monitoring
    • JSON API’s
  • 17. do not use for this...
    • CPU heavy apps
    • data transformation
  • 18. ?