SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
communities map {me}
Node.js
cosa succede ad un webserver quando
eseguiamo questa richiesta?
var orders = from o in data.Orders
where o.Amount > 10000
select o;
ShowOrders(orders);
quanto aspettiamo?
» L1-cache 3 cicli
» L2-cache 14 cicli
» RAM 250 cicli
» Disco 41.000.000 cicli
» Rete 240.000.000 cicli
soluzione (?)
web server multithreading
Apache vs NGINX 1
1
http://blog.webfaction.com/2008/12/a-little-holiday-present-10000-reqssec-with-nginx-2/
dov'è la magia?
web server single threaded,
bastato su event loop
prendiamo un modello
monothread,
asincrono
scegliamo un linguaggio
$.post("my/rest/api", function (data, status) {
alert("Data: " + data + "nStatus: " + status);
});
shakeriamo bene...
Node.Js viene presentato2
alla
European JsConf l'8 novembre
2009 da Ryan Dahl
2
https://www.youtube.com/watch?v=ztspvPYybIY
architettura
prima di iniziare...
javascript non è un
optional
scegliete con cura
web application in 5
passi
1
API3
3
https://nodejs.org/en/docs/
2
Moduli (CommonJS &
NPM)
amici in 5 minuti!
$ mkdir todo
$ cd todo
$ npm init
$ echo "console.log('hello cdays16!');" > index.js
$ node index.js
>> hello cdays16!
const http = require('http');
const hostname = '127.0.0.1';
const port = process.env.PORT || 8000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
if (req.url === '/ping') return res.end('pong!n');
return res.end('Hello World!n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
3
web framework
(express)
npm install express --save
var express = require('express');
var app = express();
app.get('/ping', (req, res) {
res.send('pong!');
});
app.patch('/api/:id', (req, res) => {
db.update(req.params.id, req.body, todo => {
res.send(createTodo(req, todo));
});
});
app.listen(process.env.PORT || 8000);
template engine
npm install jade --save
//app.js //index.jade
var express = require('express'); html
var app = express(); head
app.set('view engine', 'jade'); title!= title
body
app.get('/', (req, res) { h1!= message
res.render('index', {
title: 'cdays 2016',
message: 'hello!'
});
});
template engine Razor like
npm install vash --save
<ul class="@(model.active ? 'highlight' : '')">
@model.forEach(function(m){
<li>@m.name</li>
})
</ul>
template engine Razor like
npm install bliss --save
@!(customer,orders)
<h1>Welcome @customer.name!</h1>
<ul>
@orders.forEach(function(order){
<li>@order.title</li>
})
</ul>
4
accesso al db (knex
[+bookshelf])
npm install knex mssql pg --save
const knex = require('knex');
const connectionString = process.env.DATABASE_URL || 'postgres://postgres:pwd@localhost:5432/todo';
bug: false});
const db = knex({client: 'pg', connection: connectionString, searchPath:'knex,public'}, {debug: false});
//const db = knex({client: 'mssql',connection: connectionString,searchPath:'knex,public'}, {de
db.schema.createTableIfNotExists('items', table => {
table.increments();
table.string('title', 40).notNullable();
table.boolean('completed').defaultTo(false);
table.integer('order').defaultTo(99999);
}).asCallback((e, r) => (if (e) return console.error(e); else console.log('database ready')));
export function get (id, cb) {
db('items').select().where('id', '=', id)
.asCallback((e, r) => (if (e) return console.error(e); else cb(r[0])));
}
export function create (title, order, cb) {
db.into('items')
.insert([{'title': title, 'order': order}]).returning('*')
.asCallback((e, r) => (if (e) return console.error(e); else cb(r[0])));
}
5
autenticazione
(passport)
npm install passport passport-local --save
var passport = require('passport')
, LocalStrategy = require('passport-local').Strategy;
passport.use(new LocalStrategy(
function (username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) { return done(err); }
if (!user) return done(null, false, { message: 'Incorrect username.' });
if (!user.validPassword(password)) return done(null, false, { message: 'Incorrect password.' });
return done(null, user);
});
}
));
app.post('/login', passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/login',
failureFlash: true
})
);
npm install passport passport-twitter --save
var passport = require('passport')
, TwitterStrategy = require('passport-twitter').Strategy;
passport.use(new TwitterStrategy({
consumerKey: TWITTER_CONSUMER_KEY,
consumerSecret: TWITTER_CONSUMER_SECRET,
callbackURL: "http://www.example.com/auth/twitter/callback"
},
function(token, tokenSecret, profile, done) {
User.findOrCreate(profile, function(err, user) {
if (err) { return done(err); }
done(null, user);
});
}
));
// Redirect the user to Twitter for authentication. When complete, Twitter will redirect the user back to the application at /auth/twitter/callback
app.get('/auth/twitter', passport.authenticate('twitter'));
// Twitter will redirect the user to this URL after approval. Finish the authentication process by attempting to obtain an access token.
//If access was granted, the user will be logged in. Otherwise, authentication has failed.
app.get('/auth/twitter/callback',
passport.authenticate('twitter', { successRedirect: '/', failureRedirect: '/login' });
bonus track
unit testing
npm install mocha superhost should --save-dev
var request = require('supertest');
var should = require("should");
describe("GET /ping", function () {
it("respond 'pong!'", function (done) {
var app = require('express')();
app.get('/ping', function (req, res) {
res.send('pong!');
});
api.configure(app);
request(app).
get('/ping').
expect(200, 'pong!', done);
});
});
Node.Js cosa ci faccio?
web application
Express
desktop application
Electron
tool e plugin
(es. grunt, gulp, mocha, forever...)
cloud application
Azure Functions
Come lo lancio?
console application
foreverjs
[sudo] npm install -g forever
$ forever
usage: forever [start | stop | stopall | list] [options] SCRIPT [script options]
options:
start start SCRIPT as a daemon
stop stop the daemon SCRIPT
stopall stop all running forever scripts
list list all running forever scripts
$ forever start simple-server.js
$ forever list
[0] simple-server.js [ 24597, 24596 ]
$ forever list
[0] simple-server.js [ 24611, 24596 ]
web server
iis node module
cloud
node azure
container
docker
FROM node:6.2.2
RUN mkdir /nodejs
COPy index.js /nodejs/
WORKDIR /nodejs
ENTRYPOINT ["node", "index.js"]
EXPOSE 80
Node.Js quando?
» Tanti I/O (network, files, db…)
» Realtime application (online games, collaboration tools)
» Come «frontoffice» di un batch server (scritto in Java, .NET,
Scala….)
» Vogliamo un unico stack tecnologico tra client e server
» Vogliamo costruire velocemente tools per lo sviluppo
» Processi cpu intensive
» Logica di business complessa
» Se non si conosce bene (o si sottovaluta) JavaScript
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET

Más contenido relacionado

La actualidad más candente

Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesBram Vogelaar
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsjacekbecela
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with ExpressAaron Stannard
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changerSandro Paganotti
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기JeongHun Byeon
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev ConfTom Croucher
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr VronskiyFwdays
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupGreg DeKoenigsberg
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming Tom Croucher
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryMauro Rocco
 
Why Task Queues - ComoRichWeb
Why Task Queues - ComoRichWebWhy Task Queues - ComoRichWeb
Why Task Queues - ComoRichWebBryan Helmig
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 

La actualidad más candente (20)

Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Celery
CeleryCelery
Celery
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Europython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & CeleryEuropython 2011 - Playing tasks with Django & Celery
Europython 2011 - Playing tasks with Django & Celery
 
Express js
Express jsExpress js
Express js
 
Why Task Queues - ComoRichWeb
Why Task Queues - ComoRichWebWhy Task Queues - ComoRichWeb
Why Task Queues - ComoRichWeb
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 

Similar a Future Decoded - Node.js per sviluppatori .NET

Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationBen Hall
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsOhad Kravchick
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)Wesley Beary
 
Kraken Front-Trends
Kraken Front-TrendsKraken Front-Trends
Kraken Front-TrendsPayPal
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!Jeff Anderson
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailCliffano Subagio
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.Mike Brevoort
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Visual Engineering
 
Kraken
KrakenKraken
KrakenPayPal
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by expressShawn Meng
 

Similar a Future Decoded - Node.js per sviluppatori .NET (20)

Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
NodeJS
NodeJSNodeJS
NodeJS
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
Kraken Front-Trends
Kraken Front-TrendsKraken Front-Trends
Kraken Front-Trends
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To Tail
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Kraken
KrakenKraken
Kraken
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 

Más de Gianluca Carucci

AI&ML Conference 2019 - Deep Learning from zero to hero
AI&ML Conference 2019 - Deep Learning from zero to heroAI&ML Conference 2019 - Deep Learning from zero to hero
AI&ML Conference 2019 - Deep Learning from zero to heroGianluca Carucci
 
Working Software 2019 - TypeScript come (forse) non lo hai mai visto
Working Software 2019 - TypeScript come (forse) non lo hai mai vistoWorking Software 2019 - TypeScript come (forse) non lo hai mai visto
Working Software 2019 - TypeScript come (forse) non lo hai mai vistoGianluca Carucci
 
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai vistoKLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai vistoGianluca Carucci
 
Pycon9 - Deep Learning from zero to hero
Pycon9 - Deep Learning from zero to heroPycon9 - Deep Learning from zero to hero
Pycon9 - Deep Learning from zero to heroGianluca Carucci
 
Ask The Expert - Typescript: A stitch in time saves nine
Ask The Expert - Typescript: A stitch in time saves nineAsk The Expert - Typescript: A stitch in time saves nine
Ask The Expert - Typescript: A stitch in time saves nineGianluca Carucci
 
CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...
CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...
CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...Gianluca Carucci
 

Más de Gianluca Carucci (6)

AI&ML Conference 2019 - Deep Learning from zero to hero
AI&ML Conference 2019 - Deep Learning from zero to heroAI&ML Conference 2019 - Deep Learning from zero to hero
AI&ML Conference 2019 - Deep Learning from zero to hero
 
Working Software 2019 - TypeScript come (forse) non lo hai mai visto
Working Software 2019 - TypeScript come (forse) non lo hai mai vistoWorking Software 2019 - TypeScript come (forse) non lo hai mai visto
Working Software 2019 - TypeScript come (forse) non lo hai mai visto
 
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai vistoKLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto
KLab 2019 Meetup - TypeScript come (forse) non lo hai mai visto
 
Pycon9 - Deep Learning from zero to hero
Pycon9 - Deep Learning from zero to heroPycon9 - Deep Learning from zero to hero
Pycon9 - Deep Learning from zero to hero
 
Ask The Expert - Typescript: A stitch in time saves nine
Ask The Expert - Typescript: A stitch in time saves nineAsk The Expert - Typescript: A stitch in time saves nine
Ask The Expert - Typescript: A stitch in time saves nine
 
CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...
CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...
CommunityDays 2015 - NPM, GRUNT E BOWER: IL NUOVO PACKAGE MANAGER DI VISUAL S...
 

Último

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 

Future Decoded - Node.js per sviluppatori .NET

  • 1.
  • 2.
  • 5. cosa succede ad un webserver quando eseguiamo questa richiesta? var orders = from o in data.Orders where o.Amount > 10000 select o; ShowOrders(orders);
  • 6.
  • 7. quanto aspettiamo? » L1-cache 3 cicli » L2-cache 14 cicli » RAM 250 cicli » Disco 41.000.000 cicli » Rete 240.000.000 cicli
  • 8. soluzione (?) web server multithreading
  • 9.
  • 10. Apache vs NGINX 1 1 http://blog.webfaction.com/2008/12/a-little-holiday-present-10000-reqssec-with-nginx-2/
  • 11.
  • 12.
  • 14. web server single threaded, bastato su event loop
  • 15.
  • 17. scegliamo un linguaggio $.post("my/rest/api", function (data, status) { alert("Data: " + data + "nStatus: " + status); });
  • 19. Node.Js viene presentato2 alla European JsConf l'8 novembre 2009 da Ryan Dahl 2 https://www.youtube.com/watch?v=ztspvPYybIY
  • 21.
  • 22.
  • 23. prima di iniziare... javascript non è un optional
  • 28. amici in 5 minuti! $ mkdir todo $ cd todo $ npm init $ echo "console.log('hello cdays16!');" > index.js $ node index.js >> hello cdays16!
  • 29. const http = require('http'); const hostname = '127.0.0.1'; const port = process.env.PORT || 8000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); if (req.url === '/ping') return res.end('pong!n'); return res.end('Hello World!n'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); });
  • 31. npm install express --save var express = require('express'); var app = express(); app.get('/ping', (req, res) { res.send('pong!'); }); app.patch('/api/:id', (req, res) => { db.update(req.params.id, req.body, todo => { res.send(createTodo(req, todo)); }); }); app.listen(process.env.PORT || 8000);
  • 32. template engine npm install jade --save //app.js //index.jade var express = require('express'); html var app = express(); head app.set('view engine', 'jade'); title!= title body app.get('/', (req, res) { h1!= message res.render('index', { title: 'cdays 2016', message: 'hello!' }); });
  • 33. template engine Razor like npm install vash --save <ul class="@(model.active ? 'highlight' : '')"> @model.forEach(function(m){ <li>@m.name</li> }) </ul>
  • 34. template engine Razor like npm install bliss --save @!(customer,orders) <h1>Welcome @customer.name!</h1> <ul> @orders.forEach(function(order){ <li>@order.title</li> }) </ul>
  • 35. 4 accesso al db (knex [+bookshelf])
  • 36. npm install knex mssql pg --save const knex = require('knex'); const connectionString = process.env.DATABASE_URL || 'postgres://postgres:pwd@localhost:5432/todo'; bug: false}); const db = knex({client: 'pg', connection: connectionString, searchPath:'knex,public'}, {debug: false}); //const db = knex({client: 'mssql',connection: connectionString,searchPath:'knex,public'}, {de db.schema.createTableIfNotExists('items', table => { table.increments(); table.string('title', 40).notNullable(); table.boolean('completed').defaultTo(false); table.integer('order').defaultTo(99999); }).asCallback((e, r) => (if (e) return console.error(e); else console.log('database ready'))); export function get (id, cb) { db('items').select().where('id', '=', id) .asCallback((e, r) => (if (e) return console.error(e); else cb(r[0]))); } export function create (title, order, cb) { db.into('items') .insert([{'title': title, 'order': order}]).returning('*') .asCallback((e, r) => (if (e) return console.error(e); else cb(r[0]))); }
  • 38. npm install passport passport-local --save var passport = require('passport') , LocalStrategy = require('passport-local').Strategy; passport.use(new LocalStrategy( function (username, password, done) { User.findOne({ username: username }, function (err, user) { if (err) { return done(err); } if (!user) return done(null, false, { message: 'Incorrect username.' }); if (!user.validPassword(password)) return done(null, false, { message: 'Incorrect password.' }); return done(null, user); }); } )); app.post('/login', passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login', failureFlash: true }) );
  • 39. npm install passport passport-twitter --save var passport = require('passport') , TwitterStrategy = require('passport-twitter').Strategy; passport.use(new TwitterStrategy({ consumerKey: TWITTER_CONSUMER_KEY, consumerSecret: TWITTER_CONSUMER_SECRET, callbackURL: "http://www.example.com/auth/twitter/callback" }, function(token, tokenSecret, profile, done) { User.findOrCreate(profile, function(err, user) { if (err) { return done(err); } done(null, user); }); } )); // Redirect the user to Twitter for authentication. When complete, Twitter will redirect the user back to the application at /auth/twitter/callback app.get('/auth/twitter', passport.authenticate('twitter')); // Twitter will redirect the user to this URL after approval. Finish the authentication process by attempting to obtain an access token. //If access was granted, the user will be logged in. Otherwise, authentication has failed. app.get('/auth/twitter/callback', passport.authenticate('twitter', { successRedirect: '/', failureRedirect: '/login' });
  • 41. npm install mocha superhost should --save-dev var request = require('supertest'); var should = require("should"); describe("GET /ping", function () { it("respond 'pong!'", function (done) { var app = require('express')(); app.get('/ping', function (req, res) { res.send('pong!'); }); api.configure(app); request(app). get('/ping'). expect(200, 'pong!', done); }); });
  • 42. Node.Js cosa ci faccio?
  • 45. tool e plugin (es. grunt, gulp, mocha, forever...)
  • 48. console application foreverjs [sudo] npm install -g forever $ forever usage: forever [start | stop | stopall | list] [options] SCRIPT [script options] options: start start SCRIPT as a daemon stop stop the daemon SCRIPT stopall stop all running forever scripts list list all running forever scripts $ forever start simple-server.js $ forever list [0] simple-server.js [ 24597, 24596 ] $ forever list [0] simple-server.js [ 24611, 24596 ]
  • 51. container docker FROM node:6.2.2 RUN mkdir /nodejs COPy index.js /nodejs/ WORKDIR /nodejs ENTRYPOINT ["node", "index.js"] EXPOSE 80
  • 53. » Tanti I/O (network, files, db…) » Realtime application (online games, collaboration tools) » Come «frontoffice» di un batch server (scritto in Java, .NET, Scala….) » Vogliamo un unico stack tecnologico tra client e server » Vogliamo costruire velocemente tools per lo sviluppo
  • 54. » Processi cpu intensive » Logica di business complessa » Se non si conosce bene (o si sottovaluta) JavaScript