SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Ian Oxley
Super Mondays, 26 Sept 2011
• Hi, I’m Ian
• Web / Application Developer at Sage
• http://ianoxley.com
• @ianoxley
What is Node?

“Node is a set of libraries for JavaScript that allows it to run
outside the browser. It is primarily focused on creating simple, easy
to build network clients and servers.”
•   Event loop approach

    • Easy and safe to build scalable
      servers

• All I/O should be non-blocking
• Use asynchronous callbacks to handle
    events
var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
}).listen(8124, "127.0.0.1");

console.log('Server running at http://
127.0.0.1:8124/');
Parallel I/O
•   Node assumes all I/O has unbounded
    latency

    •   0 to infinity time

• Easy to do parallel I/O:
 • Use events as placeholders

 • Fire callbacks as events happen
Serial I/O
•   Ordered serial I/O

    • Each task completes before the next
      one starts

• Nested callbacks
 • Pyramid code - hard to understand
      and maintain
// Nesting callbacks to produce serial requests

server.on('request', function(req, res) {
  //get session information from memcached
  memcached.getSession(req, function(session) {
    //get information from db
    db.get(session.user, function(userData) {
      //some other web service call
      ws.get(req, function(wsData) {
        //render page
        page = pageRender(req, session, userData, wsData);
        //output the response
        res.write(page);
      });
    });
  });
});
// Using declared functions to seperate out code

var render = function(wsData) {
   page = pageRender(req, session, userData, wsData);
};

var getWsInfo = function(userData) {
   ...
};

var getDbInfo = function(session) {
   ...
};

var getMemCached = function(req, res) {
   ...
};
Node events

• Potentially infinite based on what’s
  happening on the server

• e.g. HTTP server module has a
  “request” event
EventEmitter

• No DOM in Node so we have the
  EventEmitter class

• Main two methods: on and emit

• Inherit from EventEmitter to attach it’s
  methods to your class
var util = require('util'),
    EventEmitter = require('events').EventEmitter;

var Server = function() {
   console.log('init');
};

util.inherits(Server, EventEmitter);
var s = new Server();

s.on('wtf', function() {
  console.log('wtf');
});

s.emit('wtf');
Modules
•   Node uses CommonJS module system:
    http://www.commonjs.org/

•   One module per file approach e.g. the
    file foo.js contains the foo module

•   Add functions and variables to the
    exports object - everything else is
// circle.js
var PI = Math.PI;

exports.area = function (r) {
   return PI * r * r;
};

exports.circumference = function (r) {
   return 2 * PI * r;
};
Where to get Node
• Official site: http://nodejs.org

• Download:
  • Source code for OS X / Linux

  • .exe for Windows
• Wiki: https://github.com/joyent/node/wiki
?

Weitere ähnliche Inhalte

Was ist angesagt?

NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrencypgriess
 
Bucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introductionBucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introductiondshkolnikov
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs Irfan Maulana
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS IntroNgoc Dao
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJSHüseyin BABAL
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with ExpressAaron Stannard
 
Real Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioReal Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioMindfire Solutions
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleKnoldus Inc.
 
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
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorDigicomp Academy AG
 
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
 

Was ist angesagt? (20)

NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
 
Express node js
Express node jsExpress node js
Express node js
 
node.js dao
node.js daonode.js dao
node.js dao
 
Bucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introductionBucks County Tech Meetup: node.js introduction
Bucks County Tech Meetup: node.js introduction
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 
Packer
Packer Packer
Packer
 
Packer by HashiCorp
Packer by HashiCorpPacker by HashiCorp
Packer by HashiCorp
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
Real Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioReal Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.io
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 
Node azure
Node azureNode azure
Node azure
 
Node ppt
Node pptNode ppt
Node ppt
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
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
 
Express JS
Express JSExpress JS
Express JS
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
 
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
 

Andere mochten auch

Forms in html5
Forms in html5Forms in html5
Forms in html5hrisi87
 
Funcion de demanda (corregido)
Funcion de demanda (corregido)Funcion de demanda (corregido)
Funcion de demanda (corregido)juan zamora moreno
 
Desenvolvimento Regional - 3a aula
Desenvolvimento Regional - 3a aulaDesenvolvimento Regional - 3a aula
Desenvolvimento Regional - 3a aulaMárcio Melânia
 
html 5 new form attribute
html 5 new form attributehtml 5 new form attribute
html 5 new form attributePriyanka Rasal
 
UL Certificate of Compliance (FFT) for Listed Systems
UL Certificate of Compliance (FFT) for Listed SystemsUL Certificate of Compliance (FFT) for Listed Systems
UL Certificate of Compliance (FFT) for Listed SystemsFire Fluid Technologies - MEA
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Gil Fink
 
Reporting on Mid Year Data - Reading Growth
Reporting on Mid Year Data - Reading GrowthReporting on Mid Year Data - Reading Growth
Reporting on Mid Year Data - Reading GrowthKaycee Salmacia
 
Investigating Mid-Year Data - Standards Mastery
Investigating Mid-Year Data - Standards MasteryInvestigating Mid-Year Data - Standards Mastery
Investigating Mid-Year Data - Standards MasteryKaycee Salmacia
 
Investigating Mid-Year Data - Reading Growth
Investigating Mid-Year Data - Reading GrowthInvestigating Mid-Year Data - Reading Growth
Investigating Mid-Year Data - Reading GrowthKaycee Salmacia
 
An Introduction to HTML5
An Introduction to HTML5An Introduction to HTML5
An Introduction to HTML5Steven Chipman
 
HTML5 and CSS3 refresher
HTML5 and CSS3 refresherHTML5 and CSS3 refresher
HTML5 and CSS3 refresherIvano Malavolta
 
Desenvolvimento Regional - 1a aula
Desenvolvimento Regional - 1a aulaDesenvolvimento Regional - 1a aula
Desenvolvimento Regional - 1a aulaMárcio Melânia
 
HTML5 presentations on SlideShare
HTML5 presentations on SlideShareHTML5 presentations on SlideShare
HTML5 presentations on SlideShareNikhil Chandna
 
Touch-Screen Displays
Touch-Screen DisplaysTouch-Screen Displays
Touch-Screen DisplaysJeffrey Funk
 

Andere mochten auch (20)

Forms in html5
Forms in html5Forms in html5
Forms in html5
 
Funcion de demanda (corregido)
Funcion de demanda (corregido)Funcion de demanda (corregido)
Funcion de demanda (corregido)
 
Desenvolvimento Regional - 3a aula
Desenvolvimento Regional - 3a aulaDesenvolvimento Regional - 3a aula
Desenvolvimento Regional - 3a aula
 
Momotaro
MomotaroMomotaro
Momotaro
 
ISO 9001 Certificate
ISO 9001 CertificateISO 9001 Certificate
ISO 9001 Certificate
 
Funcion de oferta 2
Funcion de oferta 2Funcion de oferta 2
Funcion de oferta 2
 
html 5 new form attribute
html 5 new form attributehtml 5 new form attribute
html 5 new form attribute
 
UL Certificate of Compliance (FFT) for Listed Systems
UL Certificate of Compliance (FFT) for Listed SystemsUL Certificate of Compliance (FFT) for Listed Systems
UL Certificate of Compliance (FFT) for Listed Systems
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
HTML - 5 - Introduction
HTML - 5 - IntroductionHTML - 5 - Introduction
HTML - 5 - Introduction
 
Introduction to HTML5 and CSS3
Introduction to HTML5 and CSS3Introduction to HTML5 and CSS3
Introduction to HTML5 and CSS3
 
Reporting on Mid Year Data - Reading Growth
Reporting on Mid Year Data - Reading GrowthReporting on Mid Year Data - Reading Growth
Reporting on Mid Year Data - Reading Growth
 
Investigating Mid-Year Data - Standards Mastery
Investigating Mid-Year Data - Standards MasteryInvestigating Mid-Year Data - Standards Mastery
Investigating Mid-Year Data - Standards Mastery
 
Investigating Mid-Year Data - Reading Growth
Investigating Mid-Year Data - Reading GrowthInvestigating Mid-Year Data - Reading Growth
Investigating Mid-Year Data - Reading Growth
 
An Introduction to HTML5
An Introduction to HTML5An Introduction to HTML5
An Introduction to HTML5
 
Html5
Html5Html5
Html5
 
HTML5 and CSS3 refresher
HTML5 and CSS3 refresherHTML5 and CSS3 refresher
HTML5 and CSS3 refresher
 
Desenvolvimento Regional - 1a aula
Desenvolvimento Regional - 1a aulaDesenvolvimento Regional - 1a aula
Desenvolvimento Regional - 1a aula
 
HTML5 presentations on SlideShare
HTML5 presentations on SlideShareHTML5 presentations on SlideShare
HTML5 presentations on SlideShare
 
Touch-Screen Displays
Touch-Screen DisplaysTouch-Screen Displays
Touch-Screen Displays
 

Ähnlich wie Node.js

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRichard Lee
 
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
 
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
 
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
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The WhenFITC
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
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
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
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
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileAmazon Web Services Japan
 
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
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introductionPrasoon Kumar
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsOhad Kravchick
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsRichard Rodger
 
Server Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetServer Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetTom Croucher
 

Ähnlich wie Node.js (20)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to 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
 
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
 
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?
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
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
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
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...
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
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...
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 
20120816 nodejsdublin
20120816 nodejsdublin20120816 nodejsdublin
20120816 nodejsdublin
 
Server Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetServer Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yet
 

Kürzlich hochgeladen

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 

Kürzlich hochgeladen (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
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
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 

Node.js

  • 2. • Hi, I’m Ian • Web / Application Developer at Sage • http://ianoxley.com • @ianoxley
  • 3. What is Node? “Node is a set of libraries for JavaScript that allows it to run outside the browser. It is primarily focused on creating simple, easy to build network clients and servers.”
  • 4. Event loop approach • Easy and safe to build scalable servers • All I/O should be non-blocking • Use asynchronous callbacks to handle events
  • 5. var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(8124, "127.0.0.1"); console.log('Server running at http:// 127.0.0.1:8124/');
  • 6.
  • 7. Parallel I/O • Node assumes all I/O has unbounded latency • 0 to infinity time • Easy to do parallel I/O: • Use events as placeholders • Fire callbacks as events happen
  • 8. Serial I/O • Ordered serial I/O • Each task completes before the next one starts • Nested callbacks • Pyramid code - hard to understand and maintain
  • 9. // Nesting callbacks to produce serial requests server.on('request', function(req, res) { //get session information from memcached memcached.getSession(req, function(session) { //get information from db db.get(session.user, function(userData) { //some other web service call ws.get(req, function(wsData) { //render page page = pageRender(req, session, userData, wsData); //output the response res.write(page); }); }); }); });
  • 10. // Using declared functions to seperate out code var render = function(wsData) { page = pageRender(req, session, userData, wsData); }; var getWsInfo = function(userData) { ... }; var getDbInfo = function(session) { ... }; var getMemCached = function(req, res) { ... };
  • 11.
  • 12. Node events • Potentially infinite based on what’s happening on the server • e.g. HTTP server module has a “request” event
  • 13. EventEmitter • No DOM in Node so we have the EventEmitter class • Main two methods: on and emit • Inherit from EventEmitter to attach it’s methods to your class
  • 14. var util = require('util'), EventEmitter = require('events').EventEmitter; var Server = function() { console.log('init'); }; util.inherits(Server, EventEmitter); var s = new Server(); s.on('wtf', function() { console.log('wtf'); }); s.emit('wtf');
  • 15. Modules • Node uses CommonJS module system: http://www.commonjs.org/ • One module per file approach e.g. the file foo.js contains the foo module • Add functions and variables to the exports object - everything else is
  • 16. // circle.js var PI = Math.PI; exports.area = function (r) { return PI * r * r; }; exports.circumference = function (r) { return 2 * PI * r; };
  • 17.
  • 18. Where to get Node • Official site: http://nodejs.org • Download: • Source code for OS X / Linux • .exe for Windows • Wiki: https://github.com/joyent/node/wiki
  • 19. ?

Hinweis der Redaktion

  1. \n
  2. Hi, I’m Ian. I’m a Web Developer at Sage. And today I’m going to give you a quick overview of Node.js\n
  3. According to nodejs.org it’s “evented I/O for V8 JavaScript”\nIt’s essentially the V8 engine in Google Chrome running outside the browser on the server. And as you can see from the slide it’s primary focus is on making it simple and easy to build network clients and servers.\n
  4. \n
  5. Node uses an event loop architecture. Event loops work by polling some internal or external event provider, then dispatching the event by calling the relevant event handler.\n\nNode comes with a set of non-blocking modules which simplify access to slow resources, such as the file system, that operate in an event-driven way. For example, if you make a request to the file system with Node you don’t have to wait for the hard drive to spin up and retrieve the file - the non-blocking interface simply notifies Node when it has access the same way a browser notifies your code about an onclick event.\n\nTwo strategies to follow when writing code:\n1. Once setup completed, make all actions event driven\n2. For long running tasks consider delegating to Web Workers\n
  6. \n
  7. Any time you introduce threads you then have to start worrying about race conditions, deadlock and livelock\n
  8. ...one of these...\n
  9. ...and one of these.\n\nOrdering a pint in a pub is a synchronous operation. You queue at the bar, tell the barman what you want, wait for the barman to pour your drink, pay then get your drink.\n\nStarbucks on the other hand uses a more asynchronous process. You place your order, the cashier marks the cup with your order then places it in the queue for the barista. The barista makes up the drinks whilst the cashier is busy taking more orders / requests.\n\nUsing asynchronous callbacks is nothing new in JavaScript. It’s where the first ‘A’ in Ajax comes from: Asynchronous JavaScript and XML.\n
  10. \n
  11. \n
  12. Because we’re making this assumption about unbounded latency it makes it pretty easy to do parallel tasks. We just need to make calls for various I/O tasks using our events as placeholders. They’ll return whenever they’re ready in whatever order that happens to be.\n
  13. \n
  14. \n
  15. \n
  16. JavaScript in the browser has the DOM to provide it with events. The list of possible events is limited and they are typically triggered by some sort of user interaction with the page e.g. clicking a link, moving the mouse, submitting a form and so on.\n
  17. In Node.js we aren’t limited to the events we can handle in the same way we are in the browser and can, in theory, handle any type of events that we like e.g. HTTP server module emits a request event when a user sends the Web server a request.\n\nBut without the DOM and the user interaction, how do we go about setting up these events and then handling them when the occur?\n
  18. EventEmitter is a interface psuedo-class, so if you’re creating a class that inherits from EventEmitter you’ll need to instantiate it with the ‘new’ keyword.\nIf your class inherits from EventEmitter you’ll attach it’s methods to your class.\nLets look at an example...\n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. Full instructions for building from source are on the site\nNode comes with a REPL / interactive mode - similar to those you get with Python and Ruby\nWiki contains loads of useful info such as: modules e.g. database, templating and SMTP, hosting\n
  25. \n