Node.js

7,815 views

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,815
On SlideShare
0
From Embeds
0
Number of Embeds
4,311
Actions
Shares
0
Downloads
56
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Node.js

  1. 1. j@n-dillmann.de 25. Mai 2011Design and Construction of Distributed Enterprise Applications TU Darmstadt, SS 2011
  2. 2. What? ”Nodes goal is to provide an easy way to build scalable network programs.“ —nodejs.org 2
  3. 3. How?Keeping slowoperations fromblocking otheroperations. 3
  4. 4. Traditional I/Ovar results = db.query("SELECT * FROM TABLE");// zzzzZZZzzzzzfor (var i=0; i<results.length; i++) { // process query result}// do something else 4
  5. 5. Asynchronous I/Odb.query("SELECT * FROM TABLE", function(results) { for (var i=0; i<results.length; i++) { // process query result }});// do something else immediately 5
  6. 6. And how many threads?ONLY ONE THREAD?! threading aint free easy to code no deadlocks no race-conditions 6
  7. 7. var http = require(http); e. js ttpsqlitvar sqlite3 = require(sqlite3); $ node hvar db = new sqlite3.Database(sample.db);http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); db.all("SELECT * FROM names", function (err, rows) { rows.forEach(function(row) { response.write(row.name + + row.surname + ( + row.email + )n); }); response.end(); });}).listen(8000);console.log("Running at http://127.0.0.1:8000/"); 7
  8. 8. But how does it work?client node http sqlite db create server console.log listen on 8000 request SELECT * FROM ... execute query get rows write response response 8
  9. 9. In other words:”With an eventloop, you ask it todo something anditll get back to youwhen its done.“ —@davidpadbury 9
  10. 10. So … what is in there? com piles Java ide Scri rS t pt t rve rip Ass o Se Sc embl er J ava GOOGLE V8 ted op even Lo I/OEv ent file LIBEV LIBEIO … and more 10
  11. 11. node.js 101Server Side JavaScriptBuilt on Googles V8Evented, non-blocking I/OSingle threadedEverything is asynchronousModules for (nearly) everythingCurrently only for unix-based systems available ** on Windows, you can try cygwin, but that is like asking for trouble... 11
  12. 12. Where to go next?http://nodejs.orghttp://howtonode.orghttp://chaosradio.ccc.de/cre167.htmlhttp://groups.google.com/group/nodejshttp://github.com/joyent/node/wiki/modules 12

×