Roma linuxday 2013 - nodejs

12
node.js - javascript ovunque Roma, 26 ottobre 2013 LinuxDay Roma 2013 Valerio Coltrè . Claudio Mignanti .

description

Presentazione al linux Day di Roma della piattaforma node.js, npm e connessioni con progetti come Grunt, Express e Phone-Gap

Transcript of Roma linuxday 2013 - nodejs

Page 1: Roma linuxday 2013 - nodejs

node.js - javascript ovunqueRoma, 26 ottobre 2013

LinuxDay Roma 2013

Valerio Coltrè → . ←Claudio Mignanti .

Page 2: Roma linuxday 2013 - nodejs

Cosa è

node.js è una piattaforma basata su V8, motore di google che interpreta javascript:● facile approccio per gli sviluppatori HTML5● poche risorse richieste● programmazione single thread● webserver scriptabile in js● perfetto per applicazioni

data-intensive

1. http://nodejs.org/2. http://mashable.com/2011/03/10/node-js/ http://goo.gl/4VuKS6

Page 3: Roma linuxday 2013 - nodejs

V8, l’interprete

V8 è l'engine javascript originalmentesviluppato per Chrome.

1. http://code.google.com/p/v8/

● Molto veloce, profiling avanzato.● Completamente opensource.

http://goo.gl/4VuKS6

Page 4: Roma linuxday 2013 - nodejs

Dove si usa

Ambiti d'uso:● REST API (JSON)● NodeCopter● Coder for Raspberry PI● Web Developer Tools (Grunt, Bower)

Altri punti a favore:● community molto aperta e fervente● performance cpu-bound & data-bound.● nuove tecnologie (websocket)

http://goo.gl/4VuKS6

Page 5: Roma linuxday 2013 - nodejs

javascript

Caratteristiche:● linguaggio che supporta l'OOP● interpretato a runtime● debolmente tipato

http://goo.gl/4VuKS6

Assi nella manica:● closure● prototipizzazione● regex native (senza librerie)● funzioni anonime native● simple to learn, hard to master

Page 6: Roma linuxday 2013 - nodejs

event loop

Gli interpreti javascript sono single thread● basato su eventi

○ funzioni in listening sull'evento● stack di chiamate● accesso asincrono alle risorse

http://goo.gl/4VuKS6

Specificatamente per nodejs:● possibilità di accesso sincrono al filesystem● buffer● multiprocesso● ...ed altre nodejs API

Page 7: Roma linuxday 2013 - nodejs

npm - node package manager

http://goo.gl/4VuKS6

nodejs è basato su moduli● AMD-compliant● ogni modulo é isolato (fn wrap)

Per gestire le (complesse) dipendenze c'è NPM

moduli famosi:● express Sinatra inspired web development framework

● async Higher-order functions and common patterns for async. code

● grunt The JavaScript Task Runner

● phone-gap allows you to create mobile apps using standardized web APIs

Page 8: Roma linuxday 2013 - nodejs

package.json

Gestisce le dipendenze con altri moduli nodejs

● Scaffold veloce con npm init● non re-inventare la ruota● moduli utili anche < 100 righe● one line install

http://goo.gl/4VuKS6

http://package.json.nodejitsu.com/

Page 9: Roma linuxday 2013 - nodejs

package.json

http://goo.gl/4VuKS6

Page 10: Roma linuxday 2013 - nodejs

Cosa si puo’ fare con nodejs:

Esempio pratico - tail -f

http://goo.gl/4VuKS6

tail.js → chunked.js● comportamento analogo a tail -f● versione web● chunked response (HTTP 1.1)

http://goo.gl/6Ozcc9

Page 11: Roma linuxday 2013 - nodejs

API di nodejs utilizzate:● http - web server● fs - lettura filesystem● stream in lettura/scrittura

Esempio pratico - tail -f

http://goo.gl/4VuKS6

http://nodejs.org/api/

http://goo.gl/6Ozcc9

Page 12: Roma linuxday 2013 - nodejs

conclusioni

? ← https://github.com/claudyus https://github.com/mrgamer → https://github.com/TopCS

http://goo.gl/4VuKS6 →