breve introduzione a node.js

564 views

Published on

Una breve, brevissima introduzione a node.js.

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

  • Be the first to like this

No Downloads
Views
Total views
564
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

breve introduzione a node.js

  1. 1. Un progetto di Ryan DahlUna presentazione di Eugenio Pombi NetMeansNet s.n.c.
  2. 2. Node.js èServer-side JavaScript interpreterScritto in C++Event driven (non blocking I/O)
  3. 3. $result = mysql_query(SELECT * WHERE 1=1);//do something Cosa fa apache mentre vengono recuperati i dati in attesa di essere mostrati?
  4. 4. Aspetta...E tiene impegnate risorse hardware nellattesa (RAM e CPU) Apache apre un thread per ogni nuova connessione
  5. 5. $result = mysql_query(SELECT * WHERE 1=1);//do something Questo codice implica che lintero processo si blocca durante lattesa Oppure Multiple execution stacks
  6. 6. Event Loopdb.query(SELECT * WHERE 1=1, function(result){ //do something});Questo codice permette di tornare allevent loop liberando le risorse Javascript evented programming
  7. 7. //server.jsvar sys = require( "util" ), http = require( "http" );http.createServer( function( request, response ) { response.writeHead( 200, {"Content-Type": "text/html"} ); response.write( "Hello World!" ); response.close();}).listen( 8080 );sys.puts( "Server running at http://localhost:8080" );
  8. 8. var sys = require("util"),// [...] http, url, path, fshttp.createServer(function(request, response) { var uri = url.parse(request.url).pathname; var filename = path.join(process.cwd(), uri); path.exists(filename, function(exists) { if(!exists) { response.writeHead(404, {"Content-Type": "text/plain"}); response.write("404 Not Foundn"); response.end(); return; } fs.readFile(filename, "binary", function(err, file) { if(err) { response.writeHead(500, {"Content-Type": "text/plain"}); response.write(err + "n"); response.end(); return; } response.writeHead(200); response.write(file, "binary"); response.end(); }); });}).listen(8080);sys.puts("Server running at http://localhost:8081/");
  9. 9. Cosa può fareLeggere cookieRicevere dati da formRicevere dati dalla querystringGestire gli headerUploadare filesFile streamingP2P (chat e simili)[...]Sistema modulare (npm)
  10. 10. Framework Express Geddy TDD ready Expresso nodeUnit Consigli Occhio ai tutorial con codice vecchio ;) response.close() > response.end()var sys = require("sys") > var util = require("util") http://nodetuts.com http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html
  11. 11. GRAZIE Eugenio Pombieugenio@netmeans.net @euxpom info@netmeans.net

×