ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Un progetto di  Ryan Dahl Una presentazione di Eugenio Pombi NetMeansNet s.n.c.
Node.js è Server-side JavaScript interpreter Scritto in C++ Event driven (non blocking I/O)
$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\n "); 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/" );
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]

More Related Content

Similar to 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
netmeansnet
Ìý
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in Jquery
Alberto Buschettu
Ìý
Progetto di Basi di Dati
Progetto di Basi di DatiProgetto di Basi di Dati
Progetto di Basi di Dati
segarva
Ìý
Consigli per iniziare tdd
Consigli per iniziare tddConsigli per iniziare tdd
Consigli per iniziare tdd
Tassoman ☺
Ìý
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
lordarthas
Ìý
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi plugin
Pasquale Puzio
Ìý
node.js e Postgresql
node.js e Postgresqlnode.js e Postgresql
node.js e Postgresql
Lucio Grenzi
Ìý
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con Scala
Franco Lombardo
Ìý
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
Alessandro Martin
Ìý
Java Advanced
Java AdvancedJava Advanced
Java Advanced
Antonio Furone
Ìý
Ajax
AjaxAjax
Ajax
davide ficano
Ìý
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQuery
XeDotNet
Ìý
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 web
Andrea Lazzarotto
Ìý
Applicazioni native in java
Applicazioni native in javaApplicazioni native in java
Applicazioni native in java
Federico Paparoni
Ìý
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storage
ameft
Ìý
JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)
jampslide
Ìý
Js intro
Js introJs intro
Js intro
Daniele Cruciani
Ìý
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
Dominopoint - Italian Lotus User Group
Ìý
Php e mysql (primi passi)
Php e mysql (primi passi)Php e mysql (primi passi)
Php e mysql (primi passi)
Sergio Roselli ✫✫✫
Ìý
breve introduzione a node.js
breve introduzione a node.jsbreve introduzione a node.js
breve introduzione a node.js
netmeansnet
Ìý
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in Jquery
Alberto Buschettu
Ìý
Progetto di Basi di Dati
Progetto di Basi di DatiProgetto di Basi di Dati
Progetto di Basi di Dati
segarva
Ìý
Consigli per iniziare tdd
Consigli per iniziare tddConsigli per iniziare tdd
Consigli per iniziare tdd
Tassoman ☺
Ìý
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
lordarthas
Ìý
jQuery e i suoi plugin
jQuery e i suoi pluginjQuery e i suoi plugin
jQuery e i suoi plugin
Pasquale Puzio
Ìý
node.js e Postgresql
node.js e Postgresqlnode.js e Postgresql
node.js e Postgresql
Lucio Grenzi
Ìý
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con Scala
Franco Lombardo
Ìý
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
Alessandro Martin
Ìý
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQuery
XeDotNet
Ìý
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 web
Andrea Lazzarotto
Ìý
Applicazioni native in java
Applicazioni native in javaApplicazioni native in java
Applicazioni native in java
Federico Paparoni
Ìý
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storage
ameft
Ìý
JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)JAMP DAY 2010 - ROMA (3)
JAMP DAY 2010 - ROMA (3)
jampslide
Ìý

More from eugenio pombi (7)

Parlo al mio codice
Parlo al mio codiceParlo al mio codice
Parlo al mio codice
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 roma
eugenio 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 Backgrid
eugenio pombi
Ìý
Codemotion workshop
Codemotion workshopCodemotion workshop
Codemotion workshop
eugenio pombi
Ìý
Arduino - il mio primo sketch
Arduino - il mio primo sketchArduino - il mio primo sketch
Arduino - il mio primo sketch
eugenio pombi
Ìý
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
eugenio pombi
Ìý
Appetite comes with testing
Appetite comes with testingAppetite comes with testing
Appetite comes with testing
eugenio pombi
Ìý
Parlo al mio codice
Parlo al mio codiceParlo al mio codice
Parlo al mio codice
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 roma
eugenio 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 Backgrid
eugenio pombi
Ìý
Codemotion workshop
Codemotion workshopCodemotion workshop
Codemotion workshop
eugenio pombi
Ìý
Arduino - il mio primo sketch
Arduino - il mio primo sketchArduino - il mio primo sketch
Arduino - il mio primo sketch
eugenio pombi
Ìý
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
eugenio pombi
Ìý
Appetite comes with testing
Appetite comes with testingAppetite comes with testing
Appetite comes with testing
eugenio pombi
Ìý

breve introduzione a node.js

  • 1. Un progetto di Ryan Dahl Una presentazione di Eugenio Pombi NetMeansNet s.n.c.
  • 2. Node.js è Server-side JavaScript interpreter Scritto 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 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\n "); 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ò 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]