node.js presentation to LUG Rome 2013, describing how to achieve a 'tail -f' functionality with node.js in few lines
1 of 12
Downloaded 15 times
More Related Content
node.js everywhere
1. node.js - javascript ovunque
Roma, 26 ottobre 2013
LinuxDay Roma 2013
Valerio Coltr竪 .
Claudio Mignanti .
2. 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
3. V8, linterprete
V8 竪 l'engine javascript originalmente
sviluppato per Chrome.
1. http://code.google.com/p/v8/
Molto veloce, profiling avanzato.
Completamente opensource.
http://goo.gl/4VuKS6
4. 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
5. 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
6. 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
7. 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
8. 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/
10. 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
11. 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