SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
Node.js
“This is the node.js project: to provide a purely
evented non-blocking infrastructure to script highly
concurrent programs.” - Ryan Dahl
by Shelly Seroussi & Hannah Kim
Node.js is...
● Builds fast, scalable network applications.
● Wrapper to Google’s V8 Javascript runtime.
● Event driven with nonblocking libraries.
contents = File.read(‘/etc/hosts’)
puts “#{contents}”
puts ‘Hello Flatiron’
fs.readFile(‘/etc/hosts’, function(err, contents){
console.log(contents);
});
console.log(‘Hello Flatiron’);
Blocking Code - Ruby
Non-Blocking Code - Node.js
Blocking Code
Non-Blocking Code
Listening
For Events
Known EventsEvent Queue
close
connection
request
connection
close
The Event Loop
Express
● Middleware Using Connect
● URLs Routing as Callbacks
● Redirection Helpers
● File Uploads
● Environment Based Configuration
Socket.io
● Real-time Event-based Communication
● Abstracts Websockets
● Browser Compatibility
Server.js
var express = require('express');
var socket = require('socket.io');
var app = express();
// LISTEN FOR REQUESTS
var server = app.listen(3000);
var io = socket.listen(server);
-----
// ROUTES
app.get('/', function(req, res){
res.render('index', {
title: 'title'
});
});
// Initialize Socket.io
var socket = io.connect('/');
socket.on('user:connect', function(user_count) {
update_user_count( user_count );
});
socket.on('user:disconnect', function(user_count) {
update_user_count( user_count );
});
var active_users = 0;
io.sockets.on('connection', function (socket) {
active_users++
io.sockets.emit('user:connect', active_users);
socket.on('disconnect', function () {
active_users--
io.sockets.emit('user:disconnect', active_users);
});
server.js
index.html
// EVENT: User is drawing something
socket.on('draw:progress', function( user, data ) {
progress_external_path( JSON.parse( data ), user );
}
});
// EVENT: User stops drawing something
socket.on('draw:end', function( user, data ) {
end_external_path( JSON.parse( data ), user );
});
// EVENT: User is drawing something
socket.on('draw:progress', function (uid, coordinates) {
io.sockets.emit('draw:progress', uid, coordinates)
});
// EVENT: User stops drawing something
socket.on('draw:end', function (uid, coordinates) {
io.sockets.emit('draw:end', uid, coordinates)
});
index.html
server.js
Node is great for
● Websocket Servers
● Fast File Upload Clients
● Ad Servers
● Real-Time Data Apps
Contact Us
Shelly Seroussi
shelly.seroussi@flatironschool.com
Hannah Kim
hannah.kim@flatironschool.com
Socket.io
var http = require(‘http’);
http.createServer(function(request, response) {
response.writeHead(200);
response.write(‘Hello, Flatiron School!’);
response.end();
}).listen(3000);
console.log(‘Listening on port 3000’);
Hello Flatiron!
package.json
---
"scripts": {
"start": "app.js"
},
"version": "0.0.0-14",
"engines": {
"node": "0.6.x"
},
"dependencies": {
"express": "^3.5.3",
"jade": "*",
"socket.io": "*"
}
}
{
"name": "drawstuff",
"subdomain": "drawstuff",
"scripts": {
"start": "server.js"
},
"version": "0.0.0-14",
"engines": {
"node": "0.6.x"
},
"dependencies": {
"express": "^3.5.3",
"jade": "*",
"socket.io": "*"
}
}
function onMouseDown(event) {
var point = event.point;
path = new Path();
path.fillColor = active_color_rgb;
path.add(event.point);
// The data we will send every 100ms on mouse drag
path_to_send = {
rgba : active_color_json,
start : event.point,
path : []
};
}
index.html
Paper.js
● Vector Graphic Library Framework
● Runs on Top of HTML5 Canvas
www.awesome.com
<< NPM >>
Node Package Management

Weitere ähnliche Inhalte

Was ist angesagt?

Getting started with node JS
Getting started with node JSGetting started with node JS
Getting started with node JSHamdi Hmidi
 
Creating real life serverless solutions with Azure Functions
Creating real life serverless solutions with Azure FunctionsCreating real life serverless solutions with Azure Functions
Creating real life serverless solutions with Azure FunctionsJan de Vries
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSCosmin Mereuta
 
Azure Mobile Services .NET Backend
Azure Mobile Services .NET BackendAzure Mobile Services .NET Backend
Azure Mobile Services .NET BackendShiju Varghese
 
WebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CCWebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CCDariusz Walczak
 
TDD With Typescript - Noam Katzir
TDD With Typescript - Noam KatzirTDD With Typescript - Noam Katzir
TDD With Typescript - Noam KatzirWix Engineering
 
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...Creating real life serverless solutions with Azure Functions - dotNet Amsterd...
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...Jan de Vries
 
New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011philogb
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineRicardo Silva
 
TechDays 2017 - Creating real life serverless solutions with azure functions
TechDays 2017 - Creating real life serverless solutions with azure functionsTechDays 2017 - Creating real life serverless solutions with azure functions
TechDays 2017 - Creating real life serverless solutions with azure functionsJan de Vries
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.Icinga
 
Scott Guthrie at Dot Net Startup meetup
Scott Guthrie at Dot Net Startup meetupScott Guthrie at Dot Net Startup meetup
Scott Guthrie at Dot Net Startup meetupMarcelo Calbucci
 
Consuming Web Services in Android
Consuming Web Services in AndroidConsuming Web Services in Android
Consuming Web Services in AndroidDavid Truxall
 
Ng init | EPI Sousse
Ng init | EPI SousseNg init | EPI Sousse
Ng init | EPI SousseHamdi Hmidi
 

Was ist angesagt? (20)

Getting started with node JS
Getting started with node JSGetting started with node JS
Getting started with node JS
 
Node.js concurrency
Node.js concurrencyNode.js concurrency
Node.js concurrency
 
Creating real life serverless solutions with Azure Functions
Creating real life serverless solutions with Azure FunctionsCreating real life serverless solutions with Azure Functions
Creating real life serverless solutions with Azure Functions
 
Azure DocumentDB
Azure DocumentDBAzure DocumentDB
Azure DocumentDB
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
Azure Mobile Services .NET Backend
Azure Mobile Services .NET BackendAzure Mobile Services .NET Backend
Azure Mobile Services .NET Backend
 
WebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CCWebUI - rapid UI development for EGS-CC
WebUI - rapid UI development for EGS-CC
 
TDD With Typescript - Noam Katzir
TDD With Typescript - Noam KatzirTDD With Typescript - Noam Katzir
TDD With Typescript - Noam Katzir
 
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...Creating real life serverless solutions with Azure Functions - dotNet Amsterd...
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...
 
New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Microservices/dropwizard
Microservices/dropwizardMicroservices/dropwizard
Microservices/dropwizard
 
TechDays 2017 - Creating real life serverless solutions with azure functions
TechDays 2017 - Creating real life serverless solutions with azure functionsTechDays 2017 - Creating real life serverless solutions with azure functions
TechDays 2017 - Creating real life serverless solutions with azure functions
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.
 
Scott Guthrie at Dot Net Startup meetup
Scott Guthrie at Dot Net Startup meetupScott Guthrie at Dot Net Startup meetup
Scott Guthrie at Dot Net Startup meetup
 
Backbone Dev Talk by Max Mamis
Backbone Dev Talk by Max MamisBackbone Dev Talk by Max Mamis
Backbone Dev Talk by Max Mamis
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Consuming Web Services in Android
Consuming Web Services in AndroidConsuming Web Services in Android
Consuming Web Services in Android
 
Ng init | EPI Sousse
Ng init | EPI SousseNg init | EPI Sousse
Ng init | EPI Sousse
 

Ähnlich wie Node.js Event-Driven Non-Blocking I/O Framework(39

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
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
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The WhenFITC
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationStuart (Pid) Williams
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.jsYoann Gotthilf
 
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
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introductionParth Joshi
 
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...Matt Spradley
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
Service Worker - Reliability bits
Service Worker - Reliability bitsService Worker - Reliability bits
Service Worker - Reliability bitsjungkees
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven ProgrammingKamal Hussain
 
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
 

Ähnlich wie Node.js Event-Driven Non-Blocking I/O Framework(39 (20)

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
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
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
NodeJS
NodeJSNodeJS
NodeJS
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Event driven programming -- Node.JS
Event driven programming -- Node.JSEvent driven programming -- Node.JS
Event driven programming -- Node.JS
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
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
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Service Worker - Reliability bits
Service Worker - Reliability bitsService Worker - Reliability bits
Service Worker - Reliability bits
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Exploring Node.jS
Exploring Node.jSExploring Node.jS
Exploring Node.jS
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
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
 

Mehr von Flatiron School

How to Leverage Your Network to Land Your First Job as a Developer
How to Leverage Your Network to Land Your First Job as a DeveloperHow to Leverage Your Network to Land Your First Job as a Developer
How to Leverage Your Network to Land Your First Job as a DeveloperFlatiron School
 
Pay and Get Paid: How To Integrate Stripe Into Your App
Pay and Get Paid: How To Integrate Stripe Into Your AppPay and Get Paid: How To Integrate Stripe Into Your App
Pay and Get Paid: How To Integrate Stripe Into Your AppFlatiron School
 
Pick-a-Plex App: The Pinnacle of Cinema Experiences
Pick-a-Plex App: The Pinnacle of Cinema ExperiencesPick-a-Plex App: The Pinnacle of Cinema Experiences
Pick-a-Plex App: The Pinnacle of Cinema ExperiencesFlatiron School
 
Play Music...With Your Head: A Theremin App For Everyone
Play Music...With Your Head: A Theremin App For EveryonePlay Music...With Your Head: A Theremin App For Everyone
Play Music...With Your Head: A Theremin App For EveryoneFlatiron School
 
Four Days Out: Quick Itineraries For Last-Minute Dates
Four Days Out: Quick Itineraries For Last-Minute DatesFour Days Out: Quick Itineraries For Last-Minute Dates
Four Days Out: Quick Itineraries For Last-Minute DatesFlatiron School
 
What's a Core Image? An Image-Processing Framework on iOS and OS X
What's a Core Image? An Image-Processing Framework on iOS and OS XWhat's a Core Image? An Image-Processing Framework on iOS and OS X
What's a Core Image? An Image-Processing Framework on iOS and OS XFlatiron School
 
Intro to D3: Data-Driven Documents
Intro to D3: Data-Driven DocumentsIntro to D3: Data-Driven Documents
Intro to D3: Data-Driven DocumentsFlatiron School
 

Mehr von Flatiron School (13)

How to Leverage Your Network to Land Your First Job as a Developer
How to Leverage Your Network to Land Your First Job as a DeveloperHow to Leverage Your Network to Land Your First Job as a Developer
How to Leverage Your Network to Land Your First Job as a Developer
 
Pay and Get Paid: How To Integrate Stripe Into Your App
Pay and Get Paid: How To Integrate Stripe Into Your AppPay and Get Paid: How To Integrate Stripe Into Your App
Pay and Get Paid: How To Integrate Stripe Into Your App
 
Pick-a-Plex App: The Pinnacle of Cinema Experiences
Pick-a-Plex App: The Pinnacle of Cinema ExperiencesPick-a-Plex App: The Pinnacle of Cinema Experiences
Pick-a-Plex App: The Pinnacle of Cinema Experiences
 
Play Music...With Your Head: A Theremin App For Everyone
Play Music...With Your Head: A Theremin App For EveryonePlay Music...With Your Head: A Theremin App For Everyone
Play Music...With Your Head: A Theremin App For Everyone
 
Four Days Out: Quick Itineraries For Last-Minute Dates
Four Days Out: Quick Itineraries For Last-Minute DatesFour Days Out: Quick Itineraries For Last-Minute Dates
Four Days Out: Quick Itineraries For Last-Minute Dates
 
What's a Core Image? An Image-Processing Framework on iOS and OS X
What's a Core Image? An Image-Processing Framework on iOS and OS XWhat's a Core Image? An Image-Processing Framework on iOS and OS X
What's a Core Image? An Image-Processing Framework on iOS and OS X
 
Intro to D3: Data-Driven Documents
Intro to D3: Data-Driven DocumentsIntro to D3: Data-Driven Documents
Intro to D3: Data-Driven Documents
 
Database Opt
Database Opt Database Opt
Database Opt
 
Citi Bike Finder
Citi Bike FinderCiti Bike Finder
Citi Bike Finder
 
FOMO No Mo'
FOMO No Mo' FOMO No Mo'
FOMO No Mo'
 
JSON overview and demo
JSON overview and demoJSON overview and demo
JSON overview and demo
 
Creating Ruby Gems
Creating Ruby Gems Creating Ruby Gems
Creating Ruby Gems
 
Form Helpers
Form Helpers Form Helpers
Form Helpers
 

Node.js Event-Driven Non-Blocking I/O Framework(39

  • 1. Node.js “This is the node.js project: to provide a purely evented non-blocking infrastructure to script highly concurrent programs.” - Ryan Dahl by Shelly Seroussi & Hannah Kim
  • 2. Node.js is... ● Builds fast, scalable network applications. ● Wrapper to Google’s V8 Javascript runtime. ● Event driven with nonblocking libraries.
  • 3. contents = File.read(‘/etc/hosts’) puts “#{contents}” puts ‘Hello Flatiron’ fs.readFile(‘/etc/hosts’, function(err, contents){ console.log(contents); }); console.log(‘Hello Flatiron’); Blocking Code - Ruby Non-Blocking Code - Node.js Blocking Code Non-Blocking Code
  • 4. Listening For Events Known EventsEvent Queue close connection request connection close The Event Loop
  • 5. Express ● Middleware Using Connect ● URLs Routing as Callbacks ● Redirection Helpers ● File Uploads ● Environment Based Configuration
  • 6. Socket.io ● Real-time Event-based Communication ● Abstracts Websockets ● Browser Compatibility
  • 7. Server.js var express = require('express'); var socket = require('socket.io'); var app = express(); // LISTEN FOR REQUESTS var server = app.listen(3000); var io = socket.listen(server); ----- // ROUTES app.get('/', function(req, res){ res.render('index', { title: 'title' }); });
  • 8. // Initialize Socket.io var socket = io.connect('/'); socket.on('user:connect', function(user_count) { update_user_count( user_count ); }); socket.on('user:disconnect', function(user_count) { update_user_count( user_count ); }); var active_users = 0; io.sockets.on('connection', function (socket) { active_users++ io.sockets.emit('user:connect', active_users); socket.on('disconnect', function () { active_users-- io.sockets.emit('user:disconnect', active_users); }); server.js index.html
  • 9. // EVENT: User is drawing something socket.on('draw:progress', function( user, data ) { progress_external_path( JSON.parse( data ), user ); } }); // EVENT: User stops drawing something socket.on('draw:end', function( user, data ) { end_external_path( JSON.parse( data ), user ); }); // EVENT: User is drawing something socket.on('draw:progress', function (uid, coordinates) { io.sockets.emit('draw:progress', uid, coordinates) }); // EVENT: User stops drawing something socket.on('draw:end', function (uid, coordinates) { io.sockets.emit('draw:end', uid, coordinates) }); index.html server.js
  • 10. Node is great for ● Websocket Servers ● Fast File Upload Clients ● Ad Servers ● Real-Time Data Apps
  • 13. var http = require(‘http’); http.createServer(function(request, response) { response.writeHead(200); response.write(‘Hello, Flatiron School!’); response.end(); }).listen(3000); console.log(‘Listening on port 3000’); Hello Flatiron!
  • 14. package.json --- "scripts": { "start": "app.js" }, "version": "0.0.0-14", "engines": { "node": "0.6.x" }, "dependencies": { "express": "^3.5.3", "jade": "*", "socket.io": "*" } } { "name": "drawstuff", "subdomain": "drawstuff", "scripts": { "start": "server.js" }, "version": "0.0.0-14", "engines": { "node": "0.6.x" }, "dependencies": { "express": "^3.5.3", "jade": "*", "socket.io": "*" } }
  • 15. function onMouseDown(event) { var point = event.point; path = new Path(); path.fillColor = active_color_rgb; path.add(event.point); // The data we will send every 100ms on mouse drag path_to_send = { rgba : active_color_json, start : event.point, path : [] }; } index.html
  • 16. Paper.js ● Vector Graphic Library Framework ● Runs on Top of HTML5 Canvas
  • 18. << NPM >> Node Package Management