SlideShare une entreprise Scribd logo
1  sur  11
Un progetto di  Ryan Dahl Una presentazione di Eugenio Pombi NetMeansNet s.n.c.
Node.js è ,[object Object]
$result  = mysql_query( 'SELECT * WHERE 1=1' ); //do something Cosa fa apache mentre vengono recuperati i dati in attesa di essere mostrati?
Aspetta... E tiene impegnate risorse hardware nell'attesa (RAM e CPU) Apache apre un thread per ogni nuova connessione
$result  = mysql_query( 'SELECT * WHERE 1=1' ); //do something l'intero processo si blocca durante l'attesa Oppure Multiple execution stacks Questo codice implica che
db.query( 'SELECT * WHERE 1=1' , function( result ){ //do something }) ; Questo codice permette di tornare all'event loop liberando le risorse Event Loop Javascript evented programming
//server.js var  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 "  );
var  sys = require( "util" ), // [...] http, url, path, fs http.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 Found "); response. end (); return ; } fs. readFile (filename,  "binary" ,  function (err, file) { if(err) { response. writeHead ( 500 , { "Content-Type" :  "text/plain" }); response. write (err +  "" ); response. end (); return ; } response. writeHead ( 200 ); response. write (file,  "binary" ); response. end (); }); }); }). listen ( 8080 ); sys. puts ( "Server running at http://localhost:8081/" );
Cosa può fare Leggere cookie Ricevere dati da form  Ricevere dati dalla querystring Gestire gli header Uploadare files File streaming P2P (chat e simili) [...] Sistema modulare (npm)
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
GRAZIE Eugenio Pombi [email_address] @euxpom [email_address]

Contenu connexe

Similaire à breve introduzione a node.js

breve introduzione a node.js
breve introduzione a node.jsbreve introduzione a node.js
breve introduzione a node.jsnetmeansnet
 
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryAlberto Buschettu
 
Progetto di Basi di Dati
Progetto di Basi di DatiProgetto di Basi di Dati
Progetto di Basi di Datisegarva
 
Consigli per iniziare tdd
Consigli per iniziare tddConsigli per iniziare tdd
Consigli per iniziare tddTassoman ☺
 
Sviluppo web dall'antichità all'avanguardia e ritorno
Sviluppo web  dall'antichità all'avanguardia e ritornoSviluppo web  dall'antichità all'avanguardia e ritorno
Sviluppo web dall'antichità all'avanguardia e ritornolordarthas
 
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi pluginPasquale Puzio
 
node.js e Postgresql
node.js e Postgresqlnode.js e Postgresql
node.js e PostgresqlLucio Grenzi
 
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con ScalaFranco Lombardo
 
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance OptimizationAlessandro Martin
 
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQueryXeDotNet
 
JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)jampslide
 
Come sviluppo le applicazioni web
Come sviluppo le applicazioni webCome sviluppo le applicazioni web
Come sviluppo le applicazioni webAndrea Lazzarotto
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storageameft
 
JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)jampslide
 

Similaire à breve introduzione a node.js (20)

breve introduzione a node.js
breve introduzione a node.jsbreve introduzione a node.js
breve introduzione a node.js
 
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in Jquery
 
Progetto di Basi di Dati
Progetto di Basi di DatiProgetto di Basi di Dati
Progetto di Basi di Dati
 
Consigli per iniziare tdd
Consigli per iniziare tddConsigli per iniziare tdd
Consigli per iniziare tdd
 
Sviluppo web dall'antichità all'avanguardia e ritorno
Sviluppo web  dall'antichità all'avanguardia e ritornoSviluppo web  dall'antichità all'avanguardia e ritorno
Sviluppo web dall'antichità all'avanguardia e ritorno
 
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi plugin
 
node.js e Postgresql
node.js e Postgresqlnode.js e Postgresql
node.js e Postgresql
 
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con Scala
 
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
 
Java Advanced
Java AdvancedJava Advanced
Java Advanced
 
Ajax
AjaxAjax
Ajax
 
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQuery
 
JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)JAMP DAY 2010 - ROMA (4)
JAMP DAY 2010 - ROMA (4)
 
Come sviluppo le applicazioni web
Come sviluppo le applicazioni webCome sviluppo le applicazioni web
Come sviluppo le applicazioni web
 
Applicazioni native in java
Applicazioni native in javaApplicazioni native in java
Applicazioni native in java
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storage
 
JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)
 
Js intro
Js introJs intro
Js intro
 
Ajax - Presente e futuro delle applicazioni web
Ajax - Presente e futuro delle applicazioni webAjax - Presente e futuro delle applicazioni web
Ajax - Presente e futuro delle applicazioni web
 
Php e mysql (primi passi)
Php e mysql (primi passi)Php e mysql (primi passi)
Php e mysql (primi passi)
 

Plus de eugenio pombi

Processing one year of leading for Pug roma
Processing one year of leading for Pug romaProcessing one year of leading for Pug roma
Processing one year of leading for Pug romaeugenio pombi
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
 
Arduino - il mio primo sketch
Arduino - il mio primo sketchArduino - il mio primo sketch
Arduino - il mio primo sketcheugenio pombi
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2eugenio pombi
 
Appetite comes with testing
Appetite comes with testingAppetite comes with testing
Appetite comes with testingeugenio pombi
 

Plus de eugenio pombi (7)

Parlo al mio codice
Parlo al mio codiceParlo al mio codice
Parlo al mio codice
 
Processing one year of leading for Pug roma
Processing one year of leading for Pug romaProcessing one year of leading for Pug roma
Processing one year of leading for Pug roma
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
Codemotion workshop
Codemotion workshopCodemotion workshop
Codemotion workshop
 
Arduino - il mio primo sketch
Arduino - il mio primo sketchArduino - il mio primo sketch
Arduino - il mio primo sketch
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
 
Appetite comes with testing
Appetite comes with testingAppetite comes with testing
Appetite comes with testing
 

breve introduzione a node.js

  • 1. Un progetto di Ryan Dahl Una presentazione di Eugenio Pombi NetMeansNet s.n.c.
  • 2.
  • 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 nell'attesa (RAM e CPU) Apache apre un thread per ogni nuova connessione
  • 5. $result = mysql_query( 'SELECT * WHERE 1=1' ); //do something l'intero processo si blocca durante l'attesa Oppure Multiple execution stacks Questo codice implica che
  • 6. db.query( 'SELECT * WHERE 1=1' , function( result ){ //do something }) ; Questo codice permette di tornare all'event loop liberando le risorse Event Loop Javascript evented programming
  • 7. //server.js var 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, fs http.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 Found "); response. end (); return ; } fs. readFile (filename, "binary" , function (err, file) { if(err) { response. writeHead ( 500 , { "Content-Type" : "text/plain" }); response. write (err + "" ); 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ò fare Leggere cookie Ricevere dati da form Ricevere dati dalla querystring Gestire gli header Uploadare files File streaming P2P (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 Pombi [email_address] @euxpom [email_address]