SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
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

                 Questo codice implica che



   l'intero processo si blocca durante l'attesa
                         Oppure


           Multiple execution stacks
Event Loop


db.query('SELECT * WHERE 1=1', function(result){
    //do something
});



Questo codice permette di tornare all'event loop liberando le risorse


                 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 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/");
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
eugenio@netmeans.net
      @euxpom




 info@netmeans.net

Weitere ähnliche Inhalte

Ähnlich wie breve introduzione a node.js

breve introduzione a node.js
breve introduzione a node.jsbreve introduzione a node.js
breve introduzione a node.jseugenio pombi
 
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
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storageameft
 
Drupal Day 2011 - Node.js e Drupal
Drupal Day 2011 - Node.js e DrupalDrupal Day 2011 - Node.js e Drupal
Drupal Day 2011 - Node.js e DrupalDrupalDay
 
SQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with SparkSQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with SparkAlessio Biasiutti
 
Php mysql e cms
Php mysql e cmsPhp mysql e cms
Php mysql e cmsorestJump
 
Introduzione a Node.js
Introduzione a Node.jsIntroduzione a Node.js
Introduzione a Node.jsMichele Capra
 
Come sviluppo le applicazioni web
Come sviluppo le applicazioni webCome sviluppo le applicazioni web
Come sviluppo le applicazioni webAndrea Lazzarotto
 
Programmazione web libera dai framework
Programmazione web libera dai frameworkProgrammazione web libera dai framework
Programmazione web libera dai frameworkFrancesca1980
 
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryAlberto Buschettu
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - GateinJBug Italy
 
Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5Pietro Polsinelli
 
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.Stefano Bianchini
 

Ähnlich wie 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
 
Php mysql3
Php mysql3Php mysql3
Php mysql3
 
Java Advanced
Java AdvancedJava Advanced
Java Advanced
 
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
 
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
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storage
 
Drupal Day 2011 - Node.js e Drupal
Drupal Day 2011 - Node.js e DrupalDrupal Day 2011 - Node.js e Drupal
Drupal Day 2011 - Node.js e Drupal
 
SQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with SparkSQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with Spark
 
Php mysql e cms
Php mysql e cmsPhp mysql e cms
Php mysql e cms
 
Introduzione a node.js
Introduzione a node.jsIntroduzione a node.js
Introduzione a node.js
 
Introduzione a Node.js
Introduzione a Node.jsIntroduzione a Node.js
Introduzione a Node.js
 
Applicazioni native in java
Applicazioni native in javaApplicazioni native in java
Applicazioni native in java
 
Corso Java 2 - AVANZATO
Corso Java 2 - AVANZATOCorso Java 2 - AVANZATO
Corso Java 2 - AVANZATO
 
Come sviluppo le applicazioni web
Come sviluppo le applicazioni webCome sviluppo le applicazioni web
Come sviluppo le applicazioni web
 
Programmazione web libera dai framework
Programmazione web libera dai frameworkProgrammazione web libera dai framework
Programmazione web libera dai framework
 
Rich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in JqueryRich Ajax Web Interfaces in Jquery
Rich Ajax Web Interfaces in Jquery
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - Gatein
 
Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5
 
Idp, passo dopo passo!
Idp, passo dopo passo!Idp, passo dopo passo!
Idp, passo dopo passo!
 
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
Sicurezza Php (giugno 2010) Stefano Bianchini presso Ce.Se.N.A.
 

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 Questo codice implica che l'intero processo si blocca durante l'attesa Oppure Multiple execution stacks
  • 6. Event Loop db.query('SELECT * WHERE 1=1', function(result){ //do something }); Questo codice permette di tornare all'event loop liberando le risorse 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 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ò 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 eugenio@netmeans.net @euxpom info@netmeans.net