node.js dao

  • 3,456 views
Uploaded on

This presentation from my speech about node.js in miniq club.

This presentation from my speech about node.js in miniq club.

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,456
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
28
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. node.js dao Vova Miguro
  • 2. What’s it all about?
  • 3. Node.js is a platform built onChrome’s JavaScript runtime foreasily building fast, scalablenetwork applications. -nodejs.org
  • 4. How?Let’s keep slow operationsfrom blocking otheroperations.
  • 5. traditional I/Ovar data = file.read(‘image.png’);//zzz...doSomething(data); something not right here...
  • 6. async I/Ofile.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 servervar http = require(http);http.createServer(function (req, res) { res.writeHead(200, {Content-Type: text/plain}); res.end(Hello Worldn);}).listen(3000);
  • 11. watch filevar fs = require(fs);fs.watchFile(system.log,function () { console.log(log changed!);});
  • 12. node & mongovar 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. node & web sockets//servervar io = require(socket.io).listen(80);io.sockets.on(connection, function (socket) { socket.emit(news, {hello:world});});//clientvar socket = io.connect(http://localhost);socket.on(news, function (data) { console.log(data);});
  • 14. let’s see...
  • 15. suited for...• real time• streaming• process monitoring• JSON API’s
  • 16. do not use for this...
  • 17. do not use for this...• CPU heavy apps• data transformation
  • 18. ?