SlideShare a Scribd company logo
Rami Sayar -@ramisayar 
Technical Evangelist 
Microsoft Canada
•Node.js Basics and Environment 
•Node Package Manager Overview 
•Web Framework Express Basics 
•WebSocketsand Socket.io basics 
•Building a Chatroom using Node.js
•Working knowledge of JavaScript and HTML5. 
Note: Slides will be made available.
Node.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
•It was created by Ryan Dahl in 2009. 
•Still considered in beta phase. 
•Latest version is v0.10.31. 
•Open-source! 
•Supports Windows, Linux, Mac OSX
Node.js is a runtime environment and library for running JavaScript applications outside the browser. 
Node.js is mostly used to run real-time server applications and shines through its performance using non-blocking I/O and asynchronous events.
•Node is great for streaming or event-based real-time applications like: 
•Chat Applications 
•Dashboards 
•Game Servers 
•Ad Servers 
•Streaming Servers 
•Online games, collaboration tools or anything meant to be real-time. 
•Node is great for when you need high levels of concurrency but little dedicated CPU time. 
•Great for writing JavaScript code everywhere!
•Microsoft 
•Yahoo! 
•LinkedIn 
•eBay 
•Dow Jones 
•Cloud9 
•The New York Times, etc…
•Five years after its debut, Node is the third most popular project onGitHub. 
•Over 2 million downloads per month. 
•Over 20 million downloads of v0.10x. 
•Over 81,000 modules onnpm. 
•Over 475meetupsworldwide talking about Node. 
Reference: http://strongloop.com/node-js/infographic/
aka.ms/node-101
Node.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
“A programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses) or messages from other programs.” –Wikipedia
•Node provides the event loop as part of the language. 
•With Node, there is no call to start the loop. 
•The loop starts and doesn’t end until the last callback is complete. 
•Event loop is run under a single thread therefore sleep() makes everything halt.
varfs=require('fs'); 
varcontents=fs.readFileSync('package.json').toString(); 
console.log(contents);
varfs=require('fs'); 
fs.readFile('package.json',function(err,buf){ 
console.log(buf.toString()); 
});
•Event loops result in callback-style programming where you break apart a program into its underlying data flow. 
•In other words, you end up splitting your program into smaller and smaller chunks until each chuck is mapped to operation with data. 
•Why? So that you don’t freeze the event loop on long-running operations (such as disk or network I/O).
http://callbackhell.com/
•A function will return a promise for an object in the future. 
•Promises can be chained together. 
•Simplify programming of asyncsystems. 
Read More: http://spin.atomicobject.com/2012/03/14/nodejs- and-asynchronous-programming-with-promises/
step1(function(value1){ 
step2(value1,function(value2){ 
step3(value2,function(value3){ 
step4(value3,function(value4){ 
//Dosomethingwithvalue4 
}); 
}); 
}); 
}); 
Q.fcall(promisedStep1) 
.then(promisedStep2) 
.then(promisedStep3) 
.then(promisedStep4) 
.then(function(value4){ 
//Dosomethingwithvalue4 
}) 
.catch(function(error){ 
//Handleanyerrorfromallabovesteps 
}) 
.done();
•James Coglan–“Callbacks are imperative, promises are functional: Node’s biggest missed opportunity” 
•https://blog.jcoglan.com/2013/03/30/callbacks-are- imperative-promises-are-functional-nodes-biggest- missed-opportunity/
Node.js 101 with Rami Sayar
•Allows you to listen for “events” and assign functions to run when events occur. 
•Each emitter can emit different types of events. 
•The “error” event is special. 
•Read More: http://code.tutsplus.com/tutorials/using-nodes- event-module--net-35941
•Streams represent data streams such as I/O. 
•Streams can be piped together like in Unix. 
varfs=require("fs"); 
//ReadFile 
fs.createReadStream("package.json") 
//WriteFile 
.pipe(fs.createWriteStream("out.json"));
•Node.js has a simple module and dependencies loading system. 
•Unix philosophy -> Node philosophy 
•Write programs that do one thing and do it well-> Write modules that do one thing and do it well.
•Call the function “require” with the path of the file or directory containing the module you would like to load. 
•Returns a variable containing all the exported functions. 
varfs=require("fs");
•Official package manager for Node. 
•Bundled and installed automatically with the environment. 
Frequent Usage: 
•npminstall --save package_name 
•npmupdate
{ 
"name":"Node101", 
"version":"0.1.0", 
"description":"FITC Node101 Presentation Code", 
"main":"1_hello_world.js", 
"author":{ 
"name":"RamiSayar", 
"email":"" 
} 
} 
http://browsenpm.org/package.json
Most Depended Upon 
•7053underscore 
•6458async 
•5591request 
•4931lodash 
•3630commander 
•3543express 
•2708optimist 
•2634coffee-script 
https://www.npmjs.org/
•Reads package.json 
•Installs the dependencies in the local node_modulesfolder 
•In global mode, it makes a node module accessible to all. 
•Can install from a folder, tarball, web, etc… 
•Can specify devor optional dependencies.
Asyncis a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. 
async.map(['file1','file2','file3'],fs.stat,function(err,results){ 
//resultsisnowanarrayofstatsforeachfile 
}); 
async.filter(['file1','file2','file3'],fs.exists,function(results){ 
//resultsnowequalsanarrayoftheexistingfiles 
}); 
async.parallel([ 
function(){}, 
function(){} 
],callback); 
async.series([ 
function(){}, 
function(){} 
]);
Request is designed to be the simplest way possible to make http calls. It supports HTTPS, streaming and follows redirects by default. 
varrequest=require('request'); request('http://www.microsoft.com',function(error,response,body){ 
if(!error&&response.statusCode==200){ 
console.log(body); 
} 
});
•Socket.IO enables real-time bidirectional event-based communication using WebSockets. 
•Requires HTTP module. 
•Can broadcast to other sockets.
•Express is a minimal, open source and flexible node.js web app framework designed to make developing websites, web apps and APIs much easier. 
•Express helps you respond to requests with route support so that you may write responses to specific URLs. Express allows you to support multiple templatingengines to simplify generating HTML.
varexpress=require('express'); 
varapp=express(); 
app.get('/',function(req,res){ 
res.json({message:'hooray!welcometoourapi!'}); 
}); 
app.listen(process.env.PORT||8080);
Node.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
•Node.js Basics and Environment 
•Node Package Manager Overview 
•Web Framework Express Basics 
•WebSocketsand Socket.io basics 
•Building a Chatroom using Node.js
Follow @ramisayar 
A chatroom for all! articles: aka.ms/node-101
©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related Content

What's hot (20)

PDF
Building a smarter application stack - service discovery and wiring for Docker
Tomas Doran
 
PPTX
Intro to Node.js (v1)
Chris Cowan
 
PDF
Building with Virtual Development Environments
Oscar Merida
 
PDF
Introduction to Node.js: What, why and how?
Christian Joudrey
 
PDF
Building with Virtual Development Environments
Oscar Merida
 
PPT
Introduction to node.js aka NodeJS
JITENDRA KUMAR PATEL
 
PPTX
Introduction to node.js by jiban
Jibanananda Sana
 
PPTX
GeekCampSG - Nodejs , Websockets and Realtime Web
Bhagaban Behera
 
PPTX
ChinaNetCloud - Zabbix Monitoring System Overview
ChinaNetCloud
 
PPTX
Node.JS and WebSockets with Faye
Matjaž Lipuš
 
PDF
Построение простого REST сервера на Node.js | Odessa Frontend Code challenge
OdessaFrontend
 
KEY
Dcjq node.js presentation
async_io
 
PPTX
Vagrant & Docker
Joao Antonio Ferreira (Parana)
 
PPT
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Renaun Erickson
 
PDF
Data Processing and Ruby in the World
SATOSHI TAGOMORI
 
PPTX
Let's server your Data
Frank van der Linden
 
PDF
Docker Container Orchestration
Fernand Galiana
 
PDF
Node.js for beginner
Sarunyhot Suwannachoti
 
PPTX
Mern stack
Eduonix
 
PDF
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
Nurul Ferdous
 
Building a smarter application stack - service discovery and wiring for Docker
Tomas Doran
 
Intro to Node.js (v1)
Chris Cowan
 
Building with Virtual Development Environments
Oscar Merida
 
Introduction to Node.js: What, why and how?
Christian Joudrey
 
Building with Virtual Development Environments
Oscar Merida
 
Introduction to node.js aka NodeJS
JITENDRA KUMAR PATEL
 
Introduction to node.js by jiban
Jibanananda Sana
 
GeekCampSG - Nodejs , Websockets and Realtime Web
Bhagaban Behera
 
ChinaNetCloud - Zabbix Monitoring System Overview
ChinaNetCloud
 
Node.JS and WebSockets with Faye
Matjaž Lipuš
 
Построение простого REST сервера на Node.js | Odessa Frontend Code challenge
OdessaFrontend
 
Dcjq node.js presentation
async_io
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Renaun Erickson
 
Data Processing and Ruby in the World
SATOSHI TAGOMORI
 
Let's server your Data
Frank van der Linden
 
Docker Container Orchestration
Fernand Galiana
 
Node.js for beginner
Sarunyhot Suwannachoti
 
Mern stack
Eduonix
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
Nurul Ferdous
 

Viewers also liked (20)

PDF
Node Foundation Membership Overview 20160907
NodejsFoundation
 
PPTX
Playing nice with the MEAN stack
Aspenware
 
PPTX
Object Oriented Programing in JavaScript
Akshay Mathur
 
PPTX
TypeScript 101
rachelterman
 
PPTX
Building Modern Web Apps with MEAN Stack
Suresh Patidar
 
PDF
Introduction to the MEAN stack
Yoann Gotthilf
 
PPT
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
PPTX
Introduction to Modern and Emerging Web Technologies
Suresh Patidar
 
PPTX
Starting from Scratch with the MEAN Stack
MongoDB
 
PDF
Accumulations with Nicholas Felton
FITC
 
PDF
How We Used To, How We Will
FITC
 
PDF
It’s the Experience That Makes the Product, Not the Features
FITC
 
PDF
Upgrading the Web with Douglas Crockford @ FITC's Web Unleashed 2015
FITC
 
PDF
How to SURVIVE the Creative Industry
FITC
 
PDF
Managing The Process
FITC
 
PDF
Building Apps with Ember
FITC
 
PDF
Functional Web Development
FITC
 
PPTX
Hardware for a_soft_world_bkup
FITC
 
PDF
Gamify Your Life – My Epic Quest of Awesome - Eric Boyd
FITC
 
PDF
When Clients Bare it All with David Allen
FITC
 
Node Foundation Membership Overview 20160907
NodejsFoundation
 
Playing nice with the MEAN stack
Aspenware
 
Object Oriented Programing in JavaScript
Akshay Mathur
 
TypeScript 101
rachelterman
 
Building Modern Web Apps with MEAN Stack
Suresh Patidar
 
Introduction to the MEAN stack
Yoann Gotthilf
 
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
Introduction to Modern and Emerging Web Technologies
Suresh Patidar
 
Starting from Scratch with the MEAN Stack
MongoDB
 
Accumulations with Nicholas Felton
FITC
 
How We Used To, How We Will
FITC
 
It’s the Experience That Makes the Product, Not the Features
FITC
 
Upgrading the Web with Douglas Crockford @ FITC's Web Unleashed 2015
FITC
 
How to SURVIVE the Creative Industry
FITC
 
Managing The Process
FITC
 
Building Apps with Ember
FITC
 
Functional Web Development
FITC
 
Hardware for a_soft_world_bkup
FITC
 
Gamify Your Life – My Epic Quest of Awesome - Eric Boyd
FITC
 
When Clients Bare it All with David Allen
FITC
 
Ad

Similar to Node.js 101 with Rami Sayar (20)

PDF
FITC - Node.js 101
Rami Sayar
 
PPTX
introduction to node.js
orkaplan
 
PDF
Nodejs a-practical-introduction-oredev
Felix Geisendörfer
 
ODP
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
ODP
Vert.x keynote for EclipseCon 2013
timfox111
 
PPTX
Introduction to Node (15th May 2017)
Lucas Jellema
 
PPTX
Node.js: The What, The How and The When
FITC
 
PPTX
Node.js Workshop - Sela SDP 2015
Nir Noy
 
PDF
Node.js Introduction
Kelum Senanayake
 
PPT
Introducción y comandos en NodeJS slodte
lmcsenatic
 
PPTX
Introducing Node.js in an Oracle technology environment (including hands-on)
Lucas Jellema
 
PPTX
Nodejs
Bhushan Patil
 
PPT
JavaScript Event Loop
Thomas Hunter II
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PPTX
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
PPT
Node js beginner
Sureshreddy Nalimela
 
PDF
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
PPTX
Node.js: A Guided Tour
cacois
 
PPTX
Beginners Node.js
Khaled Mosharraf
 
PPTX
Node.js on Azure
Sasha Goldshtein
 
FITC - Node.js 101
Rami Sayar
 
introduction to node.js
orkaplan
 
Nodejs a-practical-introduction-oredev
Felix Geisendörfer
 
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
Vert.x keynote for EclipseCon 2013
timfox111
 
Introduction to Node (15th May 2017)
Lucas Jellema
 
Node.js: The What, The How and The When
FITC
 
Node.js Workshop - Sela SDP 2015
Nir Noy
 
Node.js Introduction
Kelum Senanayake
 
Introducción y comandos en NodeJS slodte
lmcsenatic
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Lucas Jellema
 
JavaScript Event Loop
Thomas Hunter II
 
node.js: Javascript's in your backend
David Padbury
 
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
Node js beginner
Sureshreddy Nalimela
 
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
Node.js: A Guided Tour
cacois
 
Beginners Node.js
Khaled Mosharraf
 
Node.js on Azure
Sasha Goldshtein
 
Ad

More from FITC (20)

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

Recently uploaded (20)

PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
ZARA-Case.pptx djdkkdjnddkdoodkdxjidjdnhdjjdjx
RonnelPineda2
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPTX
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPTX
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
PDF
How to Fix Error Code 16 in Adobe Photoshop A Step-by-Step Guide.pdf
Becky Lean
 
PPTX
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
PDF
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
PPT
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PDF
Pas45789-Energs-Efficient-Craigg1ing.pdf
lafinedelcinghiale
 
PPTX
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
PPTX
Random Presentation By Fuhran Khalil uio
maniieiish
 
PDF
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
PDF
Web Hosting for Shopify WooCommerce etc.
Harry_Phoneix Harry_Phoneix
 
PPT
introductio to computers by arthur janry
RamananMuthukrishnan
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
ZARA-Case.pptx djdkkdjnddkdoodkdxjidjdnhdjjdjx
RonnelPineda2
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
How to Fix Error Code 16 in Adobe Photoshop A Step-by-Step Guide.pdf
Becky Lean
 
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
Pas45789-Energs-Efficient-Craigg1ing.pdf
lafinedelcinghiale
 
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
Random Presentation By Fuhran Khalil uio
maniieiish
 
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
Web Hosting for Shopify WooCommerce etc.
Harry_Phoneix Harry_Phoneix
 
introductio to computers by arthur janry
RamananMuthukrishnan
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 

Node.js 101 with Rami Sayar

  • 1. Rami Sayar -@ramisayar Technical Evangelist Microsoft Canada
  • 2. •Node.js Basics and Environment •Node Package Manager Overview •Web Framework Express Basics •WebSocketsand Socket.io basics •Building a Chatroom using Node.js
  • 3. •Working knowledge of JavaScript and HTML5. Note: Slides will be made available.
  • 10. •It was created by Ryan Dahl in 2009. •Still considered in beta phase. •Latest version is v0.10.31. •Open-source! •Supports Windows, Linux, Mac OSX
  • 11. Node.js is a runtime environment and library for running JavaScript applications outside the browser. Node.js is mostly used to run real-time server applications and shines through its performance using non-blocking I/O and asynchronous events.
  • 12. •Node is great for streaming or event-based real-time applications like: •Chat Applications •Dashboards •Game Servers •Ad Servers •Streaming Servers •Online games, collaboration tools or anything meant to be real-time. •Node is great for when you need high levels of concurrency but little dedicated CPU time. •Great for writing JavaScript code everywhere!
  • 13. •Microsoft •Yahoo! •LinkedIn •eBay •Dow Jones •Cloud9 •The New York Times, etc…
  • 14. •Five years after its debut, Node is the third most popular project onGitHub. •Over 2 million downloads per month. •Over 20 million downloads of v0.10x. •Over 81,000 modules onnpm. •Over 475meetupsworldwide talking about Node. Reference: http://strongloop.com/node-js/infographic/
  • 18. “A programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses) or messages from other programs.” –Wikipedia
  • 19. •Node provides the event loop as part of the language. •With Node, there is no call to start the loop. •The loop starts and doesn’t end until the last callback is complete. •Event loop is run under a single thread therefore sleep() makes everything halt.
  • 22. •Event loops result in callback-style programming where you break apart a program into its underlying data flow. •In other words, you end up splitting your program into smaller and smaller chunks until each chuck is mapped to operation with data. •Why? So that you don’t freeze the event loop on long-running operations (such as disk or network I/O).
  • 24. •A function will return a promise for an object in the future. •Promises can be chained together. •Simplify programming of asyncsystems. Read More: http://spin.atomicobject.com/2012/03/14/nodejs- and-asynchronous-programming-with-promises/
  • 25. step1(function(value1){ step2(value1,function(value2){ step3(value2,function(value3){ step4(value3,function(value4){ //Dosomethingwithvalue4 }); }); }); }); Q.fcall(promisedStep1) .then(promisedStep2) .then(promisedStep3) .then(promisedStep4) .then(function(value4){ //Dosomethingwithvalue4 }) .catch(function(error){ //Handleanyerrorfromallabovesteps }) .done();
  • 26. •James Coglan–“Callbacks are imperative, promises are functional: Node’s biggest missed opportunity” •https://blog.jcoglan.com/2013/03/30/callbacks-are- imperative-promises-are-functional-nodes-biggest- missed-opportunity/
  • 28. •Allows you to listen for “events” and assign functions to run when events occur. •Each emitter can emit different types of events. •The “error” event is special. •Read More: http://code.tutsplus.com/tutorials/using-nodes- event-module--net-35941
  • 29. •Streams represent data streams such as I/O. •Streams can be piped together like in Unix. varfs=require("fs"); //ReadFile fs.createReadStream("package.json") //WriteFile .pipe(fs.createWriteStream("out.json"));
  • 30. •Node.js has a simple module and dependencies loading system. •Unix philosophy -> Node philosophy •Write programs that do one thing and do it well-> Write modules that do one thing and do it well.
  • 31. •Call the function “require” with the path of the file or directory containing the module you would like to load. •Returns a variable containing all the exported functions. varfs=require("fs");
  • 32. •Official package manager for Node. •Bundled and installed automatically with the environment. Frequent Usage: •npminstall --save package_name •npmupdate
  • 33. { "name":"Node101", "version":"0.1.0", "description":"FITC Node101 Presentation Code", "main":"1_hello_world.js", "author":{ "name":"RamiSayar", "email":"" } } http://browsenpm.org/package.json
  • 34. Most Depended Upon •7053underscore •6458async •5591request •4931lodash •3630commander •3543express •2708optimist •2634coffee-script https://www.npmjs.org/
  • 35. •Reads package.json •Installs the dependencies in the local node_modulesfolder •In global mode, it makes a node module accessible to all. •Can install from a folder, tarball, web, etc… •Can specify devor optional dependencies.
  • 36. Asyncis a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. async.map(['file1','file2','file3'],fs.stat,function(err,results){ //resultsisnowanarrayofstatsforeachfile }); async.filter(['file1','file2','file3'],fs.exists,function(results){ //resultsnowequalsanarrayoftheexistingfiles }); async.parallel([ function(){}, function(){} ],callback); async.series([ function(){}, function(){} ]);
  • 37. Request is designed to be the simplest way possible to make http calls. It supports HTTPS, streaming and follows redirects by default. varrequest=require('request'); request('http://www.microsoft.com',function(error,response,body){ if(!error&&response.statusCode==200){ console.log(body); } });
  • 38. •Socket.IO enables real-time bidirectional event-based communication using WebSockets. •Requires HTTP module. •Can broadcast to other sockets.
  • 39. •Express is a minimal, open source and flexible node.js web app framework designed to make developing websites, web apps and APIs much easier. •Express helps you respond to requests with route support so that you may write responses to specific URLs. Express allows you to support multiple templatingengines to simplify generating HTML.
  • 40. varexpress=require('express'); varapp=express(); app.get('/',function(req,res){ res.json({message:'hooray!welcometoourapi!'}); }); app.listen(process.env.PORT||8080);
  • 43. •Node.js Basics and Environment •Node Package Manager Overview •Web Framework Express Basics •WebSocketsand Socket.io basics •Building a Chatroom using Node.js
  • 44. Follow @ramisayar A chatroom for all! articles: aka.ms/node-101
  • 45. ©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.