Your SlideShare is downloading. ×
breve introduzione a node.js
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

breve introduzione a node.js

408

Published on

Una breve, brevissima introduzione a node.js.

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
408
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
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

Transcript

  • 1. Un progetto di Ryan DahlUna presentazione di Eugenio Pombi NetMeansNet s.n.c.
  • 2. Node.js èServer-side JavaScript interpreterScritto in C++Event driven (non blocking I/O)
  • 3. $result = mysql_query(SELECT * WHERE 1=1);//do something Cosa fa apache mentre vengono recuperati i dati in attesa di essere mostrati?
  • 4. Aspetta...E tiene impegnate risorse hardware nellattesa (RAM e CPU) Apache apre un thread per ogni nuova connessione
  • 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. 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. //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. 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. Cosa può fareLeggere cookieRicevere dati da formRicevere dati dalla querystringGestire gli headerUploadare filesFile streamingP2P (chat e simili)[...]Sistema modulare (npm)
  • 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. GRAZIE Eugenio Pombieugenio@netmeans.net @euxpom info@netmeans.net

×