SlideShare une entreprise Scribd logo
1  sur  25
Intro to Node.JS
By Aaron Stannard
Startup Developer Evangelist, Microsoft Corporation
Examples from Today’s Talk
https://github.com/Aaronontheweb/introtonode
Meet Node
var http = require('http');
//Node function called each time a new HTTP request arrives
function onRequest(req, res){
res.writeHead(200, {'Content-Type':'text/plain'});
res.end('Hello ' + req.connection.remoteAddress + '!');
/* Write the IP addresses of our connecting client to console */
console.log('Incoming connection from ' +
req.connection.remoteAddress);
}
//Listen for connections on the port provided by the host process
var server = http.createServer(onRequest).listen(process.env.PORT);
What Is Node?
• Server Side JavaScript
• Asynchronous Web Framework
• Evented I/O Model
What Is Node?
Network I/O Libraries
+
+
=
What Makes Node Special?
• Uses the familiar JavaScript programming
model to enable server-side development
• Buries the pain of working with async /
parallel programming
• No Blocking I/O
• Can handle large concurrent loads more easily
than other technologies
• Not a silver bullet
Why Node
JavaScript is ubiquitous
Why Node
Traditional Platforms
• Things you need for
concurrent web
programming:
– Locks
– Threads / Thread Pools
– Thread Management
– Inter-Thread Communication
– Callbacks + Enclosures + Sync
to Blocking Calls
Node
• Things you need for
concurrent web
programming:
– Callbacks + Enclosures
Which looks
simpler?
Good Node Scenarios
Behavior
• High request volume, low
response-sizes
• Pub / Sub
• Real-time applications
Application
• Online games, message
passing services
• Social networks, content-
syndication services
• Chat, real-time games
Bad Node Scenarios
Behavior
• Large HTTP response sizes
• CRUD
• Transaction-heavy systems
Application
• Static file servers, reporting
tools
• Blogs, CMS
• E-Commerce
Node Concepts
• What Do Node Projects Look Like?
• Event Loop & Workers
• HTTP as a First Class Citizen
• Callbacks and Functions as Objects
• Modules & Packages
Structure of a Node Project
/projectroot/
package.json
readme.txt
web/
server.js
views/
index.html
models/
post.js
helpers/
timestamp.js
test/
route-test.js
post-test.js
node_modules/
C:[projectroot]> node web/server.js
Node server listenening on port 3000 in development mode
Tells Node and NPM what packages are required
The main entry point for your application
User-defined module for handling persistence
User-defined module for other stuff
Root of your actual application
Directory for unit tests
Output directory for all NPM installations
Event Loop + Workers
HTTP
• HTTP is a first class citizen
• Request Object
– Holds properties about the client
– Holds session state
– Passes client-data to request handlers
• Response Object
– Holds the HTTP response stream
– Can be written in chunks
Callbacks and Functions as Objects
// HTTP GET /app/list
exports.listapps = function(req, res){
var pageTitle = req.session.userName + "'s Apps";
appProvider.getAppsForUser(req.session.userName,
function(error, userApps){
if(error){
console.log(error.message);
return res.redirect('/');
}
res.render('list_apps', {locals:{title: pageTitle,
apps:userApps}})
});
}
Modules & Packages
• Including a built-in module
var http = require('http');
• Including your own module
[timestamp.js] exports.currentTime = function(){…}
[server.js] var timestamp = require(‘./helpers/timestamp');
[server.js] console.log(timestamp.currentTime());
• Node Package Manager (NPM)
[Commandline] C:> npm install express
[server.js] var express = require(‘express’);
Microsoft & Node
Microsoft wants Windows Azure to be an option
for developers regardless of stack
=>
Node on Windows Azure
• IISNode
• Windows Azure Node PowerShell Cmdlets
• Windows Azure Node SDK
• Cloud9 IDE
IISNode
• Hosts Node applications in IIS as native
modules
• Automatically manages life-cycle of node.exe
• Can load-balance multiple node.exe processes
Azure / Node Powershell Cmdlets
• Create new Azure Services
• Add Node Web and Worker Roles
• Deploy to Azure Emulator
• Import Publish Settings
• Deploy to Azure (Production / Staging)
• Source @ Github
Windows Azure SDK
• Loads Storage Settings from Web.config
• Azure Tables
• Azure Blobs
• Azure Queues
[console] C:> npm install azure
Source @ Github
Cloud9 IDE
• Browser-based IDE
• Deploys to Windows Azure
• Only way to deploy without Windows Vista / 7
Popular Node Frameworks and Tools
• Express (MVC)
• Connect
• Socket.IO
• Unit Testing:
– Assert (built-in)
– Nodeunit
Further Reference
• NodeBeginner.org - Used this to teach myself
Node when I was first getting started.
• NodeJS.org - Official Node Homepage
• Github.com/WindowsAzure – Azure bits
About Me
• Aaron Stannard
– Twitter: @Aaronontheweb
– Github: @Aaronontheweb
– Blog: http://www.aaronstannard.com/

Contenu connexe

Tendances

Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Visual Engineering
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JSCakra Danu Sedayu
 
Nodejs first class
Nodejs first classNodejs first class
Nodejs first classFin Chen
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event EmittersTheCreativedev Blog
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.jsdavidchubbs
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node jsfakedarren
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersCaldera Labs
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by expressShawn Meng
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswanivvaswani
 
Head First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & ApplicationHead First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & ApplicationJace Ju
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to CeleryIdan Gazit
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Caldera Labs
 
What happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingWhat happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingJace Ju
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications Juliana Lucena
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCalderaLearn
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationAbdul Malik Ikhsan
 

Tendances (20)

Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
Nodejs first class
Nodejs first classNodejs first class
Nodejs first class
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Head First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & ApplicationHead First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & Application
 
An Introduction to Celery
An Introduction to CeleryAn Introduction to Celery
An Introduction to Celery
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
 
What happens in laravel 4 bootstraping
What happens in laravel 4 bootstrapingWhat happens in laravel 4 bootstraping
What happens in laravel 4 bootstraping
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 

Similaire à Intro to Node.JS: Server-Side JavaScript and Event-Driven Programming

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
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
 
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
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The ApproachHaci Murat Yaman
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRichard Lee
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleGeoff Ballinger
 
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
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesciklum_ods
 
Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.jsAyush Mishra
 
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
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Masahiro Nagano
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js PlatformNaresh Chintalcheru
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparisonHiroshi Nakamura
 

Similaire à Intro to Node.JS: Server-Side JavaScript and Event-Driven Programming (20)

Node.js
Node.jsNode.js
Node.js
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
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...
 
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...
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's Finagle
 
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
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
 
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
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 

Plus de Aaron Stannard

The Coming OSS Sustainability Crisis
The Coming OSS Sustainability CrisisThe Coming OSS Sustainability Crisis
The Coming OSS Sustainability CrisisAaron Stannard
 
Startup Product Development
Startup Product DevelopmentStartup Product Development
Startup Product DevelopmentAaron Stannard
 
NoSQL Shootout: RavenDB vs MongoDB
NoSQL Shootout: RavenDB vs MongoDBNoSQL Shootout: RavenDB vs MongoDB
NoSQL Shootout: RavenDB vs MongoDBAaron Stannard
 
Location Services and Bing Maps in Windows Phone 7
Location Services and Bing Maps in Windows Phone 7Location Services and Bing Maps in Windows Phone 7
Location Services and Bing Maps in Windows Phone 7Aaron Stannard
 
Consuming REST in .NET
Consuming REST in .NETConsuming REST in .NET
Consuming REST in .NETAaron Stannard
 
How to Design Applications People Love
How to Design Applications People LoveHow to Design Applications People Love
How to Design Applications People LoveAaron Stannard
 

Plus de Aaron Stannard (7)

The Coming OSS Sustainability Crisis
The Coming OSS Sustainability CrisisThe Coming OSS Sustainability Crisis
The Coming OSS Sustainability Crisis
 
Startup Product Development
Startup Product DevelopmentStartup Product Development
Startup Product Development
 
NoSQL Shootout: RavenDB vs MongoDB
NoSQL Shootout: RavenDB vs MongoDBNoSQL Shootout: RavenDB vs MongoDB
NoSQL Shootout: RavenDB vs MongoDB
 
Location Services and Bing Maps in Windows Phone 7
Location Services and Bing Maps in Windows Phone 7Location Services and Bing Maps in Windows Phone 7
Location Services and Bing Maps in Windows Phone 7
 
Consuming REST in .NET
Consuming REST in .NETConsuming REST in .NET
Consuming REST in .NET
 
MVVM for n00bs
MVVM for n00bsMVVM for n00bs
MVVM for n00bs
 
How to Design Applications People Love
How to Design Applications People LoveHow to Design Applications People Love
How to Design Applications People Love
 

Dernier

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Dernier (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Intro to Node.JS: Server-Side JavaScript and Event-Driven Programming

  • 1. Intro to Node.JS By Aaron Stannard Startup Developer Evangelist, Microsoft Corporation
  • 2. Examples from Today’s Talk https://github.com/Aaronontheweb/introtonode
  • 3. Meet Node var http = require('http'); //Node function called each time a new HTTP request arrives function onRequest(req, res){ res.writeHead(200, {'Content-Type':'text/plain'}); res.end('Hello ' + req.connection.remoteAddress + '!'); /* Write the IP addresses of our connecting client to console */ console.log('Incoming connection from ' + req.connection.remoteAddress); } //Listen for connections on the port provided by the host process var server = http.createServer(onRequest).listen(process.env.PORT);
  • 4. What Is Node? • Server Side JavaScript • Asynchronous Web Framework • Evented I/O Model
  • 5. What Is Node? Network I/O Libraries + + =
  • 6. What Makes Node Special? • Uses the familiar JavaScript programming model to enable server-side development • Buries the pain of working with async / parallel programming • No Blocking I/O • Can handle large concurrent loads more easily than other technologies • Not a silver bullet
  • 8. Why Node Traditional Platforms • Things you need for concurrent web programming: – Locks – Threads / Thread Pools – Thread Management – Inter-Thread Communication – Callbacks + Enclosures + Sync to Blocking Calls Node • Things you need for concurrent web programming: – Callbacks + Enclosures Which looks simpler?
  • 9. Good Node Scenarios Behavior • High request volume, low response-sizes • Pub / Sub • Real-time applications Application • Online games, message passing services • Social networks, content- syndication services • Chat, real-time games
  • 10. Bad Node Scenarios Behavior • Large HTTP response sizes • CRUD • Transaction-heavy systems Application • Static file servers, reporting tools • Blogs, CMS • E-Commerce
  • 11. Node Concepts • What Do Node Projects Look Like? • Event Loop & Workers • HTTP as a First Class Citizen • Callbacks and Functions as Objects • Modules & Packages
  • 12. Structure of a Node Project /projectroot/ package.json readme.txt web/ server.js views/ index.html models/ post.js helpers/ timestamp.js test/ route-test.js post-test.js node_modules/ C:[projectroot]> node web/server.js Node server listenening on port 3000 in development mode Tells Node and NPM what packages are required The main entry point for your application User-defined module for handling persistence User-defined module for other stuff Root of your actual application Directory for unit tests Output directory for all NPM installations
  • 13. Event Loop + Workers
  • 14. HTTP • HTTP is a first class citizen • Request Object – Holds properties about the client – Holds session state – Passes client-data to request handlers • Response Object – Holds the HTTP response stream – Can be written in chunks
  • 15. Callbacks and Functions as Objects // HTTP GET /app/list exports.listapps = function(req, res){ var pageTitle = req.session.userName + "'s Apps"; appProvider.getAppsForUser(req.session.userName, function(error, userApps){ if(error){ console.log(error.message); return res.redirect('/'); } res.render('list_apps', {locals:{title: pageTitle, apps:userApps}}) }); }
  • 16. Modules & Packages • Including a built-in module var http = require('http'); • Including your own module [timestamp.js] exports.currentTime = function(){…} [server.js] var timestamp = require(‘./helpers/timestamp'); [server.js] console.log(timestamp.currentTime()); • Node Package Manager (NPM) [Commandline] C:> npm install express [server.js] var express = require(‘express’);
  • 17. Microsoft & Node Microsoft wants Windows Azure to be an option for developers regardless of stack =>
  • 18. Node on Windows Azure • IISNode • Windows Azure Node PowerShell Cmdlets • Windows Azure Node SDK • Cloud9 IDE
  • 19. IISNode • Hosts Node applications in IIS as native modules • Automatically manages life-cycle of node.exe • Can load-balance multiple node.exe processes
  • 20. Azure / Node Powershell Cmdlets • Create new Azure Services • Add Node Web and Worker Roles • Deploy to Azure Emulator • Import Publish Settings • Deploy to Azure (Production / Staging) • Source @ Github
  • 21. Windows Azure SDK • Loads Storage Settings from Web.config • Azure Tables • Azure Blobs • Azure Queues [console] C:> npm install azure Source @ Github
  • 22. Cloud9 IDE • Browser-based IDE • Deploys to Windows Azure • Only way to deploy without Windows Vista / 7
  • 23. Popular Node Frameworks and Tools • Express (MVC) • Connect • Socket.IO • Unit Testing: – Assert (built-in) – Nodeunit
  • 24. Further Reference • NodeBeginner.org - Used this to teach myself Node when I was first getting started. • NodeJS.org - Official Node Homepage • Github.com/WindowsAzure – Azure bits
  • 25. About Me • Aaron Stannard – Twitter: @Aaronontheweb – Github: @Aaronontheweb – Blog: http://www.aaronstannard.com/

Notes de l'éditeur

  1. Designed for Data-Intensive & Real-Time Web Applications
  2. Server-Side (!!) JavaScript Built on top of the Chrome V8 Engine Designed for data-intensive & real-time web applications Everything is asynchronous
  3. Scenarios: Large request volume, low response size Multiplayer games Social / real-time applications Pub/Sub Uses a language universal to all web developers Allows developers with no prior back-end experience to leverage their skills for real applications
  4. Callbacks and the Programming Model Closures Functions as Objects Design Patterns
  5. HTML5-based IDE Free to use $12/mo for private projects Deploys to Windows Azure Hides ~90% of the configuration stuff