SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

PDF
Getting started with node JS
Hamdi Hmidi
 
PDF
Node.js concurrency
Giacomo Fornari
 
PPTX
Creating real life serverless solutions with Azure Functions
Jan de Vries
 
PPSX
Azure DocumentDB
Shiju Varghese
 
PPTX
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 
PPSX
Azure Mobile Services .NET Backend
Shiju Varghese
 
PDF
WebUI - rapid UI development for EGS-CC
Dariusz Walczak
 
PPTX
TDD With Typescript - Noam Katzir
Wix Engineering
 
PPTX
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...
Jan de Vries
 
PDF
New Tools for Visualization in JavaScript - Sept. 2011
philogb
 
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
PPTX
Microservices/dropwizard
FKM Naimul Huda, PMP
 
PPTX
TechDays 2017 - Creating real life serverless solutions with azure functions
Jan de Vries
 
PDF
Building interactivity with websockets
Wim Godden
 
PPTX
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.
Icinga
 
PPTX
Scott Guthrie at Dot Net Startup meetup
Marcelo Calbucci
 
PDF
Backbone Dev Talk by Max Mamis
Prolific Interactive
 
PDF
MongoDB and Node.js
Norberto Leite
 
PDF
Consuming Web Services in Android
David Truxall
 
PDF
Ng init | EPI Sousse
Hamdi Hmidi
 
Getting started with node JS
Hamdi Hmidi
 
Node.js concurrency
Giacomo Fornari
 
Creating real life serverless solutions with Azure Functions
Jan de Vries
 
Azure DocumentDB
Shiju Varghese
 
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 
Azure Mobile Services .NET Backend
Shiju Varghese
 
WebUI - rapid UI development for EGS-CC
Dariusz Walczak
 
TDD With Typescript - Noam Katzir
Wix Engineering
 
Creating real life serverless solutions with Azure Functions - dotNet Amsterd...
Jan de Vries
 
New Tools for Visualization in JavaScript - Sept. 2011
philogb
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
Microservices/dropwizard
FKM Naimul Huda, PMP
 
TechDays 2017 - Creating real life serverless solutions with azure functions
Jan de Vries
 
Building interactivity with websockets
Wim Godden
 
Icinga Camp Bangalore - Icinga2 API use cases and BlueJeans Inc.
Icinga
 
Scott Guthrie at Dot Net Startup meetup
Marcelo Calbucci
 
Backbone Dev Talk by Max Mamis
Prolific Interactive
 
MongoDB and Node.js
Norberto Leite
 
Consuming Web Services in Android
David Truxall
 
Ng init | EPI Sousse
Hamdi Hmidi
 

Similar to Into to Node.js: Building Fast, Scaleable Network Applications (20)

KEY
Writing robust Node.js applications
Tom Croucher
 
PDF
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
KEY
Practical Use of MongoDB for Node.js
async_io
 
PPTX
NodeJS
Alok Guha
 
PPT
Node js beginner
Sureshreddy Nalimela
 
PPTX
Node.js: The What, The How and The When
FITC
 
PDF
Introduction to Node.js
Somkiat Puisungnoen
 
PDF
Nodejs and WebSockets
Gonzalo Ayuso
 
ODP
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
PDF
Event driven programming -- Node.JS
Dimitri Teravanessian
 
PDF
Introduction to REST API with Node.js
Yoann Gotthilf
 
PPTX
Real World Lessons on the Pain Points of Node.JS Application
Ben Hall
 
PDF
Node.js introduction
Parth Joshi
 
PPTX
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
Matt Spradley
 
PPTX
Intro to node and mongodb 1
Mohammad Qureshi
 
PDF
Service Worker - Reliability bits
jungkees
 
PPTX
Node.js Workshop - Sela SDP 2015
Nir Noy
 
PPT
Exploring Node.jS
Deepu S Nath
 
PDF
Server Side Event Driven Programming
Kamal Hussain
 
PPT
nodejs tutorial foor free download from academia
rani marri
 
Writing robust Node.js applications
Tom Croucher
 
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
Practical Use of MongoDB for Node.js
async_io
 
NodeJS
Alok Guha
 
Node js beginner
Sureshreddy Nalimela
 
Node.js: The What, The How and The When
FITC
 
Introduction to Node.js
Somkiat Puisungnoen
 
Nodejs and WebSockets
Gonzalo Ayuso
 
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
Event driven programming -- Node.JS
Dimitri Teravanessian
 
Introduction to REST API with Node.js
Yoann Gotthilf
 
Real World Lessons on the Pain Points of Node.JS Application
Ben Hall
 
Node.js introduction
Parth Joshi
 
How We Built a Mobile Electronic Health Record App Using Xamarin, Angular, an...
Matt Spradley
 
Intro to node and mongodb 1
Mohammad Qureshi
 
Service Worker - Reliability bits
jungkees
 
Node.js Workshop - Sela SDP 2015
Nir Noy
 
Exploring Node.jS
Deepu S Nath
 
Server Side Event Driven Programming
Kamal Hussain
 
nodejs tutorial foor free download from academia
rani marri
 
Ad

More from Flatiron School (13)

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

Into to Node.js: Building Fast, Scaleable Network Applications

  • 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