SlideShare uma empresa Scribd logo
1 de 40
Node.js
Awesome, Lightweight, JavaScript, High Performance

qr.net/fitc2014
WHO AM I?
•

Richard Nieuwenhuis

•

32 years old

•

MediaMonks

•

7 years a Monk

•

Lead of Operations / Head of
development
Overview
•

What is Node.js

•

Some small examples

•

Asynchrony here, asynchrony there

•

Some (popular) Node.js modules

•

Socket.io

•

High performance examples

•

Some tips & tricks
When and by whom?
•

First made public in 2009

•

Ryan Lienhart Dahl

•

Currently at version 0.10.25*

•

“Why is a progress bar so difficult?”
•

•

“Why the heck are we polling???”
This sheet was created 17-2-2014
What nodejs.org says
•

“Node.js is a platform built on Chrome's JavaScript runtime for
easily building fast, scalable network applications. Node.js uses
an event-driven, non-blocking I/O model that makes it lightweight
and efficient, perfect for data-intensive real-time applications that
run across distributed devices.”
In short how many people see it

•

Server side JavaScript!
High Level Component overview

Node.js

V8

Event Loop
(Libuv)
Where to begin?
•

Download & Install Node.js
•

•

Use your favorite IDE

Node.js API/Modules:
•
•

Sort of API‟s which expose Node functions

•

Allows the Node.js community to extend Node.js

•
•

Built-in

Super lightweight

Add-ons
•

Quite a big community

•

The NPM (Node Package Manager)
Some Node.js APIs/Modules
•

http
•

•

Provides basic functions for creating a server and handling requests

https
•

•

For setting up a secured server
assert

•
•

For creating unit tests for your code (NodeTDD!)
fs

•

For doing stuff with the File System
Some Node.js
APIs/Modules continued
•

querystring
•

•

For parsing the query string of a request
url

•
•

functions for parsing and resolving URL‟s
repl: Read-Eval-Print-Loop

•

Good for debugging and testing
Let‟s build something simple
•

Simple server
•

Every “Hello World” Example starts with this.

•

Read the files of a folder.

•

Print the file names in the browser in sorted fashion.

•

PS. Examples show Node specifics and are to illustrate points and are by no
means “elegant, save” etc :-)
Create our own module: sorterservice.js
function sortFileNames(fileNames){
return fileNames.sort();
}

exports.sortFileNames = sortFileNames;

-

a module can be a single file
a module can be a folder
exports is a special object to define properties

-

Can be any type: function, strings, etc
Requiring needed modules
//require the needed modules
var http = require('http');
var fs

= require('fs');

var sorter = require('./sorterservice');
Create server and verify requests
http.createServer(function(req, res){
switch(req.method){
case 'POST':
console.log('This is a post request');
break;
case 'GET':
switch(req.url){
case '/':
readFileNames(res);
break;
case '/showfiles„:
readFileNames(res);
break;
case '/favicon.ico„:
break;
}
break;
default:
res.setHeader('Content-Type', 'text/plain');
res.end("This method I simply do not know");
}
Let‟s read the file names
function readFileNames(res){
var dirName = './files';

var html = '';
var fileNames

= fs.readdirSync(dirName);

var sortedFileNames = sorter.sortFileNames(fileNames);
html += '<ol>';
for(var index in sortedFileNames){
html += '<li>' + sortedFileNames[index] + '</li>';
}
html += '</ol>';
sendFileNames(res, html);
}
One last thing & Does it work?

function sendFileNames(res, html){
res.setHeader('Content-Type', 'text/html');
res.end(html);
}
Two big things not OK here
Which are also two important Node aspects

1)

Error handling

2)

A-synchronous architecture
Main problem 1
function readFileNames(res){
var dirName = './files';
var html = '';

var fileNames = [];
fileNames

= fs.readdirSync(dirName);

var sortedFileNames = sorter.sortFileNames(fileNames);
html += '<ol>';
for(var index in sortedFileNames){
html += '<li>' + sortedFileNames[index] + '</li>';
}

html += '</ol>';
sendFileNames(res, html);
}
What did we see?
•

The server crashed and Node stopped running

•

A lot less forgiving than PHP for example

•

Not OK during a super bowl commercial where millions of Dollars are spend
;-)

Tip: Look at the Node.js module forever
In this case a simple
if (fs.existsSync(dirName)){
fileNames = fs.readdirSync(dirName);
}

Would suffice….
•

Defensive programming is super important in Node
•

Verify everything!

•

Valid user input

•

Expect the unexpected (even if you expect otherwise)

•

Act on any error that may occur (and log it)

•

Have a process in place to restart node just to be sure (forever module)
“Problemo” numero dos
fs.readdirSync(dirName);

Node is a single threaded running process.
Synchronous development
•

Blocking/Synchronous requests are bad

•
•

It will “block” the continuation of your logic for the amount of time the
blocking request is active (requesting a JSON file for example)

On the server you basically have the same problems

•
•

But it will affect all visitors immediately when one request is stalling
Can ultimately lead to a crashing server
Synchronous development
http.createServer(function(req, res){
switch(req.method){

case 'POST':
console.log('This is a post request');
break;

case 'GET':
//”Select *” all 200K users from the database
//Give it back to the response

}
}).listen(8888);
Continued
Pffff, I need to
return 200K
rows?

Request

Cpu to r2: Sorry, I
am doing nothing,
but the DB is
sooooo slowww

Request 2

Going to take
me a while!

doQuery()

CPU

processData()

Cpu
time

DB
The Event Loop
Take this event
loop!:
doQuery(cb)

Pffff, I need to
return 200K
rows?
Going to take me
a while!

Request

CPU to r2: thanks
man! I am
processing your
request

Request 2

CPU

processData()

E
loop

callback

DB
A-Synchronous Node development

A lot of Node functions have a-synchronous versions.
fs.readdir(dirName, function(err, data){

if (err){

console.log();
}
var sortedFileNames = sorter.sortFileNames(data);
//The other code
--------------------------http.createServer(function(req, res){……
A-Synchronous Node development
•

A-synchronize as much as possible to keep the main process as “free” as
possible.

•

•

Much more necessary when it is a high-performance environment

It is not the holy grail! Keep the Big O in mind: for (var x = 0; x < 25.5Billion;
x++)

•

Sequencing & parallel

•

Can become quite messy and unreadable
A highly unlikely hypothetical situation

•

Read the files from Dir A

•

Merge the content of all files of Dir A into one file

•

Read the files from Dir B

•

Append the content of step 1 to all files in Dir B

•

Store these results in the Database
Would look something like this
aSynReadDir('A/', function(files) {

mergeFiles(files, function(fileContents) {
aSynReadDir('B/', function(files) {
appendFiles(fileContents, files, function(appendedFiles) {

insertIntoDatabase(appendedFiles, function() {
});
});
});
});
});
Useful Node Modules: Socket.io
•

Latest browsers support Web sockets
•

IE10+

•

Chrome

•

FireFox

•

“Weirdly” on Android only starting from 4.4…

•

Socket.io leverages the Web socket technology for bi-directional
communication between clients & servers:

•

With degradability in place for the “older” browsers!
Socket.io continued
•

Very nice for real time applications with a lot of concurrent users.
•

Browser based games where you mobile is the controller

•

Second screen applications

•

Updating the client:

•

Chat

•

Real time statistics

•

News updates

•

Etc
Small example (Server)
var server = http.createServer(function(req, res){
//code here
});
var io = socketio.listen(server);
function sendRandomMessage(){
var index = Math.floor((Math.random()*4));
io.sockets.send(words[index]);
}
Small example (Client)
var socket = io.connect();
socket.on('message', function (message) {
console.log(„I received the message ' + message);
var m = document.createElement('p');
m.innerText = message;

document.getElementById('text').appendChild(m);
});
Event Listener
socket.on('message', function (message)……

socket.emit(„fired‟, {message: yep, you are fired});
Other Useful Node Modules
"dependencies": {
"express": "3.4.7", // Web Framework
"express-validator": "1.0.1",
"request": "2.25.0", //
"redis": "0.10.0", //Redis: High performance in memory DB
"hiredis": "0.1.16", // To make Redis even faster with C written stuff
"redis-sentinel": "0.0.5", // Redis failover
"http-auth": "*", //for authentication
"openid": "0.5.5", //Open ID client
"statsd-client": "*", //NodeJS deamon for logging request s
tatistics
"facebook-node-sdk": "0.2.0",
"librato-metrics": "0.0.7",
"statsd-client": "0.0.15"
}
ADIDAS
NITROCHARGE

An interactive cinematic
experience using your mobile
phone as a controller.

Produced for DDB & Tribal

Case
Video
KLM
CLAIM YOUR
PLACE IN SPACE

Are you ready to win the ultimate journey
of inspiration? Claim your spot in space

Produced for DDB & Tribal Amsterdam

Case
Video
THE VOICE
OF HOLLAND
Talpa

This season you can be a
coach at home. Show your
coaching qualities with The
Voice of Holland Thuiscoach
app.

Case
Video
THANK YOU!
•

We are looking for new awesome
developers!

•

Questions: richard@mediamonks.com

Mais conteúdo relacionado

Mais procurados

Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 
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
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)Felix Geisendörfer
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsGary Yeh
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRichard Lee
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js ExplainedJeff Kunkle
 
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Binary Studio
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleTom Croucher
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devmcantelon
 
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...Timur Shemsedinov
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJSHüseyin BABAL
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 

Mais procurados (20)

Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
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...
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
Node.js
Node.jsNode.js
Node.js
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
 
node.js dao
node.js daonode.js dao
node.js dao
 
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal dev
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 
Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 

Destaque

It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny...
 It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny... It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny...
It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny...FITC
 
高性能Javascript
高性能Javascript高性能Javascript
高性能Javascriptfangdeng
 
High performance java script why everything youve been taught is wrong
High performance java script why everything youve been taught is wrongHigh performance java script why everything youve been taught is wrong
High performance java script why everything youve been taught is wrongTao Gao
 
Sais-tu que...
Sais-tu que...Sais-tu que...
Sais-tu que...forever22
 
Business Aspects of High Performance Websites
Business Aspects of High Performance WebsitesBusiness Aspects of High Performance Websites
Business Aspects of High Performance Websitesmalteubl
 

Destaque (7)

Future of modernization
Future of modernizationFuture of modernization
Future of modernization
 
It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny...
 It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny... It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny...
It’s Not Enough To Be Brilliant – You Have To Be Convincing, Too. with Lanny...
 
高性能Javascript
高性能Javascript高性能Javascript
高性能Javascript
 
High performance java script why everything youve been taught is wrong
High performance java script why everything youve been taught is wrongHigh performance java script why everything youve been taught is wrong
High performance java script why everything youve been taught is wrong
 
Change mind about JS
Change mind about JSChange mind about JS
Change mind about JS
 
Sais-tu que...
Sais-tu que...Sais-tu que...
Sais-tu que...
 
Business Aspects of High Performance Websites
Business Aspects of High Performance WebsitesBusiness Aspects of High Performance Websites
Business Aspects of High Performance Websites
 

Semelhante a Node.js: The What, The How and The When

Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
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
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami SayarFITC
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Christian Joudrey
 
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 node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsDerek Anderson
 
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
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Ran Mizrahi
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Ran Mizrahi
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptxdipen55
 
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
 

Semelhante a Node.js: The What, The How and The When (20)

Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
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
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
 
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
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Introduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCatsIntroduction to NodeJS with LOLCats
Introduction to NodeJS with LOLCats
 
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
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Node.js
Node.jsNode.js
Node.js
 
Node.js
Node.jsNode.js
Node.js
 
5.node js
5.node js5.node js
5.node js
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
 
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
 

Mais de FITC

Cut it up
Cut it upCut it up
Cut it upFITC
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital HealthFITC
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript PerformanceFITC
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech StackFITC
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR ProjectFITC
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerFITC
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryFITC
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday InnovationFITC
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight WebsitesFITC
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is TerrifyingFITC
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanFITC
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)FITC
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameFITC
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare SystemFITC
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignFITC
 
The Power of Now
The Power of NowThe Power of Now
The Power of NowFITC
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAsFITC
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstackFITC
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFITC
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForFITC
 

Mais de FITC (20)

Cut it up
Cut it upCut it up
Cut it up
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital Health
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech Stack
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR Project
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the Answer
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s Story
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday Innovation
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight Websites
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is Terrifying
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future Human
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR Game
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare System
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product Design
 
The Power of Now
The Power of NowThe Power of Now
The Power of Now
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAs
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstack
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self Discovery
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time For
 

Último

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Último (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Node.js: The What, The How and The When

  • 1. Node.js Awesome, Lightweight, JavaScript, High Performance qr.net/fitc2014
  • 2. WHO AM I? • Richard Nieuwenhuis • 32 years old • MediaMonks • 7 years a Monk • Lead of Operations / Head of development
  • 3.
  • 4. Overview • What is Node.js • Some small examples • Asynchrony here, asynchrony there • Some (popular) Node.js modules • Socket.io • High performance examples • Some tips & tricks
  • 5. When and by whom? • First made public in 2009 • Ryan Lienhart Dahl • Currently at version 0.10.25* • “Why is a progress bar so difficult?” • • “Why the heck are we polling???” This sheet was created 17-2-2014
  • 6. What nodejs.org says • “Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”
  • 7. In short how many people see it • Server side JavaScript!
  • 8. High Level Component overview Node.js V8 Event Loop (Libuv)
  • 9. Where to begin? • Download & Install Node.js • • Use your favorite IDE Node.js API/Modules: • • Sort of API‟s which expose Node functions • Allows the Node.js community to extend Node.js • • Built-in Super lightweight Add-ons • Quite a big community • The NPM (Node Package Manager)
  • 10. Some Node.js APIs/Modules • http • • Provides basic functions for creating a server and handling requests https • • For setting up a secured server assert • • For creating unit tests for your code (NodeTDD!) fs • For doing stuff with the File System
  • 11. Some Node.js APIs/Modules continued • querystring • • For parsing the query string of a request url • • functions for parsing and resolving URL‟s repl: Read-Eval-Print-Loop • Good for debugging and testing
  • 12. Let‟s build something simple • Simple server • Every “Hello World” Example starts with this. • Read the files of a folder. • Print the file names in the browser in sorted fashion. • PS. Examples show Node specifics and are to illustrate points and are by no means “elegant, save” etc :-)
  • 13. Create our own module: sorterservice.js function sortFileNames(fileNames){ return fileNames.sort(); } exports.sortFileNames = sortFileNames; - a module can be a single file a module can be a folder exports is a special object to define properties - Can be any type: function, strings, etc
  • 14. Requiring needed modules //require the needed modules var http = require('http'); var fs = require('fs'); var sorter = require('./sorterservice');
  • 15. Create server and verify requests http.createServer(function(req, res){ switch(req.method){ case 'POST': console.log('This is a post request'); break; case 'GET': switch(req.url){ case '/': readFileNames(res); break; case '/showfiles„: readFileNames(res); break; case '/favicon.ico„: break; } break; default: res.setHeader('Content-Type', 'text/plain'); res.end("This method I simply do not know"); }
  • 16. Let‟s read the file names function readFileNames(res){ var dirName = './files'; var html = ''; var fileNames = fs.readdirSync(dirName); var sortedFileNames = sorter.sortFileNames(fileNames); html += '<ol>'; for(var index in sortedFileNames){ html += '<li>' + sortedFileNames[index] + '</li>'; } html += '</ol>'; sendFileNames(res, html); }
  • 17. One last thing & Does it work? function sendFileNames(res, html){ res.setHeader('Content-Type', 'text/html'); res.end(html); }
  • 18. Two big things not OK here Which are also two important Node aspects 1) Error handling 2) A-synchronous architecture
  • 19. Main problem 1 function readFileNames(res){ var dirName = './files'; var html = ''; var fileNames = []; fileNames = fs.readdirSync(dirName); var sortedFileNames = sorter.sortFileNames(fileNames); html += '<ol>'; for(var index in sortedFileNames){ html += '<li>' + sortedFileNames[index] + '</li>'; } html += '</ol>'; sendFileNames(res, html); }
  • 20. What did we see? • The server crashed and Node stopped running • A lot less forgiving than PHP for example • Not OK during a super bowl commercial where millions of Dollars are spend ;-) Tip: Look at the Node.js module forever
  • 21. In this case a simple if (fs.existsSync(dirName)){ fileNames = fs.readdirSync(dirName); } Would suffice…. • Defensive programming is super important in Node • Verify everything! • Valid user input • Expect the unexpected (even if you expect otherwise) • Act on any error that may occur (and log it) • Have a process in place to restart node just to be sure (forever module)
  • 22. “Problemo” numero dos fs.readdirSync(dirName); Node is a single threaded running process.
  • 23. Synchronous development • Blocking/Synchronous requests are bad • • It will “block” the continuation of your logic for the amount of time the blocking request is active (requesting a JSON file for example) On the server you basically have the same problems • • But it will affect all visitors immediately when one request is stalling Can ultimately lead to a crashing server
  • 24. Synchronous development http.createServer(function(req, res){ switch(req.method){ case 'POST': console.log('This is a post request'); break; case 'GET': //”Select *” all 200K users from the database //Give it back to the response } }).listen(8888);
  • 25. Continued Pffff, I need to return 200K rows? Request Cpu to r2: Sorry, I am doing nothing, but the DB is sooooo slowww Request 2 Going to take me a while! doQuery() CPU processData() Cpu time DB
  • 26. The Event Loop Take this event loop!: doQuery(cb) Pffff, I need to return 200K rows? Going to take me a while! Request CPU to r2: thanks man! I am processing your request Request 2 CPU processData() E loop callback DB
  • 27. A-Synchronous Node development A lot of Node functions have a-synchronous versions. fs.readdir(dirName, function(err, data){ if (err){ console.log(); } var sortedFileNames = sorter.sortFileNames(data); //The other code --------------------------http.createServer(function(req, res){……
  • 28. A-Synchronous Node development • A-synchronize as much as possible to keep the main process as “free” as possible. • • Much more necessary when it is a high-performance environment It is not the holy grail! Keep the Big O in mind: for (var x = 0; x < 25.5Billion; x++) • Sequencing & parallel • Can become quite messy and unreadable
  • 29. A highly unlikely hypothetical situation • Read the files from Dir A • Merge the content of all files of Dir A into one file • Read the files from Dir B • Append the content of step 1 to all files in Dir B • Store these results in the Database
  • 30. Would look something like this aSynReadDir('A/', function(files) { mergeFiles(files, function(fileContents) { aSynReadDir('B/', function(files) { appendFiles(fileContents, files, function(appendedFiles) { insertIntoDatabase(appendedFiles, function() { }); }); }); }); });
  • 31. Useful Node Modules: Socket.io • Latest browsers support Web sockets • IE10+ • Chrome • FireFox • “Weirdly” on Android only starting from 4.4… • Socket.io leverages the Web socket technology for bi-directional communication between clients & servers: • With degradability in place for the “older” browsers!
  • 32. Socket.io continued • Very nice for real time applications with a lot of concurrent users. • Browser based games where you mobile is the controller • Second screen applications • Updating the client: • Chat • Real time statistics • News updates • Etc
  • 33. Small example (Server) var server = http.createServer(function(req, res){ //code here }); var io = socketio.listen(server); function sendRandomMessage(){ var index = Math.floor((Math.random()*4)); io.sockets.send(words[index]); }
  • 34. Small example (Client) var socket = io.connect(); socket.on('message', function (message) { console.log(„I received the message ' + message); var m = document.createElement('p'); m.innerText = message; document.getElementById('text').appendChild(m); });
  • 35. Event Listener socket.on('message', function (message)…… socket.emit(„fired‟, {message: yep, you are fired});
  • 36. Other Useful Node Modules "dependencies": { "express": "3.4.7", // Web Framework "express-validator": "1.0.1", "request": "2.25.0", // "redis": "0.10.0", //Redis: High performance in memory DB "hiredis": "0.1.16", // To make Redis even faster with C written stuff "redis-sentinel": "0.0.5", // Redis failover "http-auth": "*", //for authentication "openid": "0.5.5", //Open ID client "statsd-client": "*", //NodeJS deamon for logging request s tatistics "facebook-node-sdk": "0.2.0", "librato-metrics": "0.0.7", "statsd-client": "0.0.15" }
  • 37. ADIDAS NITROCHARGE An interactive cinematic experience using your mobile phone as a controller. 
Produced for DDB & Tribal Case Video
  • 38. KLM CLAIM YOUR PLACE IN SPACE Are you ready to win the ultimate journey of inspiration? Claim your spot in space 
Produced for DDB & Tribal Amsterdam Case Video
  • 39. THE VOICE OF HOLLAND Talpa This season you can be a coach at home. Show your coaching qualities with The Voice of Holland Thuiscoach app. Case Video
  • 40. THANK YOU! • We are looking for new awesome developers! • Questions: richard@mediamonks.com

Notas do Editor

  1. Like MediaMonks on Facebook: https://www.facebook.com/mediamonksMore information about MediaMonks: http://www.mediamonks.com/
  2. Share your participation!Facebook share moment: “I am participating in the 2nd screen presentation of @MediaMonks @FITC”Twitter share moment: “I am participating in the 2nd screen presentation of @MediaMonks @FITC”
  3. Text: “This is Ryan Dahl”{Image of Ryan Dahl}
  4. Text: “Yep, literally copy pasted it”
  5. Text: “Nothing to say here”
  6. Text:“V8 powers the Google Chrome browser”“More information on V8: https://code.google.com/p/v8/”
  7. Text: “Download Node.js here: http://nodejs.org/”Text: “Currently around 60.000 3rd Party modules! See: https://www.npmjs.org/”
  8. Question: “What JavaScript engine is Node.js using?”v2 rocketV8V7 v18Correct answer = b
  9. Text:A closer look on your phone:“{ protocol: &apos;http:&apos;, slashes: true, auth: null, host: &apos;www.mediamonks.com&apos;, port: null, hostname: &apos;www.mediamonks.com&apos;, hash: null, search: &apos;?who=richard&amp;location=fitc&apos;, query: &apos;who=richard&amp;location=fitc&apos;, pathname: &apos;/&apos;, path: &apos;/?who=richard&amp;location=fitc&apos;,href: &apos;http://www.mediamonks.com/?who=richard&amp;location=fitc&apos; }“Note for myself:Do a repl demonstration of the following code: “require(‘url’).parse(‘http://www.mediamonks.com/?who=richard&amp;location=fitc’)”
  10. Image (ugly_code.jpg)
  11. Text: “Nothing to say here”
  12. Text: “Share moment”Facebook share: “Looking at some Node.js Code @FITC”Twitter share: “Looking at some Node.js Code @FITC”
  13. Text:“Nothing to say here”
  14. Text: “Bored? Answer the following question:”Script Language = JavaScriptWhat is the value of Y at the end of the following code snippet:var x = 7;var y = ‘’;if (x++ == 8) y = &apos;The Terminator&apos;;else y = &apos;Robocop&apos;;‘’The TerminatorRobocopError, syntax errorCorrect answer = c
  15. Text: “That was freaking awesome!”Richard notes: Show them the amazing website
  16. Image: arnold.jpg
  17. Question: What do you think is the underlying technology of this application on your mobile?PollingStored in JavaScriptSockets (and fallbacks)Correct answer: CRichard notes: show them what happens when the dir name is changed
  18. Question: “Which Node.js module did I use for reading the files?”httpnetfsnsCorrect answer = c
  19. Answer the following question:What sentencewill be printed?function justWaitAMinute(cb){setTimeout(function(){cb(); }, 60000);}var text = ‘Future’;justWaitAMinute(function(){ console.log(‘What?: ‘ + text );});var text = ‘Creativity’;What?: CreativityWoot?: CreativityWhat?: FutureCorrect answer = A
  20. Text: “Nothing to say here”Node has cluster setup
  21. Text: “You might think, DUH! ”
  22. @Richard: show them it blocks by using the slowserver.jsQuestion:Which of the following is not an HTTP methodPOSTGETHEADUPDATEDELETECorrect answer: D
  23. Text: “The important thing here is that the main process is waiting for the database to return its result, while basically doing nothing resource wise. It prevents other request of being accepted”
  24. Text: “The important thing here is that the main Node process lets the Event Loop wait for all the IO call backs. This means that the main process can continue handling request for example”
  25. Text: For if you wanted to see the rest of ht code:if (err){ console.log(&apos;Crap, dir does not exist :-(&apos;); }if (typeof data != &apos;undefined&apos;){varsortedFileNames = sorter.sortFileNames(data); }html += &apos;&lt;ol&gt;&apos;;for(var index in sortedFileNames){ html += &apos;&lt;li&gt;&apos; + sortedFileNames[index] + &apos;&lt;/li&gt;&apos;; }html += &apos;&lt;/ol&gt;&apos;;sendFileNames(res, html); });
  26. Text: “See node.js documentation here: http://nodejs.org/api/. Make sure to use the A-Synchronous variants of the functions”
  27. Question: What is the Big O of the following pseudo code snippet?data = [1 , 2, …, ………];data2 = [1, 2, …, …..];for(var x = 0; x &lt; data.length; x++){ for (var y = 0; y &lt; data2.length; y++){ //do something }}n2n3nn^3n^2Answer is e
  28. Text: “Nesting happens a lot!”
  29. People’s Choice of the Year: Adidas Nitro charge uses Socket.ioDesktop: http://www.nitrochargeyourgame.com/Image: nitro.jpg
  30. Share moment:FB &amp; Twitter share “Socket.io for the win @FITC”
  31. Text: “Nothing to say here”
  32. Text: For more information on Socket.io: http://socket.io/
  33. Text ‘Nothing to say here’
  34. Text: “This is a package.json file in which you can specify module dependancies”