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

More Related Content

What's hot

NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
pgriess
 
node.js dao
node.js daonode.js dao
node.js dao
Vladimir Miguro
 
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
dshkolnikov
 
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 NodeJS
Hüseyin BABAL
 
Packer
Packer Packer
Packer
Nitesh Saini
 
Packer by HashiCorp
Packer by HashiCorpPacker by HashiCorp
Packer by HashiCorp
Łukasz Cieśluk
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
Aaron 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.io
Mindfire Solutions
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
Aaron Stannard
 
Node azure
Node azureNode azure
Node azure
Emanuele DelBono
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
Knoldus 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.js
Yoann Gotthilf
 
Express JS
Express JSExpress JS
Express JS
Alok Guha
 
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
Digicomp 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 js
fakedarren
 

What's hot (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
 

Viewers also liked

Forms in html5
Forms in html5Forms in html5
Forms in html5
hrisi87
 
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 aula
Márcio Melânia
 
Funcion de oferta 2
Funcion de oferta 2Funcion de oferta 2
Funcion de oferta 2
juan zamora moreno
 
html 5 new form attribute
html 5 new form attributehtml 5 new form attribute
html 5 new form attribute
Priyanka 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 HTML5
Gil Fink
 
HTML - 5 - Introduction
HTML - 5 - IntroductionHTML - 5 - Introduction
HTML - 5 - Introduction
Aayushi Chhabra
 
Introduction to HTML5 and CSS3
Introduction to HTML5 and CSS3Introduction to HTML5 and CSS3
Introduction to HTML5 and CSS3
Chandra S Oemarjadi
 
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
Kaycee Salmacia
 
Investigating Mid-Year Data - Standards Mastery
Investigating Mid-Year Data - Standards MasteryInvestigating Mid-Year Data - Standards Mastery
Investigating Mid-Year Data - Standards Mastery
Kaycee Salmacia
 
Investigating Mid-Year Data - Reading Growth
Investigating Mid-Year Data - Reading GrowthInvestigating Mid-Year Data - Reading Growth
Investigating Mid-Year Data - Reading Growth
Kaycee Salmacia
 
An Introduction to HTML5
An Introduction to HTML5An Introduction to HTML5
An Introduction to HTML5
Steven Chipman
 
HTML5 and CSS3 refresher
HTML5 and CSS3 refresherHTML5 and CSS3 refresher
HTML5 and CSS3 refresher
Ivano Malavolta
 
Desenvolvimento Regional - 1a aula
Desenvolvimento Regional - 1a aulaDesenvolvimento Regional - 1a aula
Desenvolvimento Regional - 1a aula
Márcio Melânia
 
HTML5 presentations on SlideShare
HTML5 presentations on SlideShareHTML5 presentations on SlideShare
HTML5 presentations on SlideShare
Nikhil Chandna
 
Touch-Screen Displays
Touch-Screen DisplaysTouch-Screen Displays
Touch-Screen Displays
Jeffrey Funk
 

Viewers also liked (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
 

Similar to 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.js
soft-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.js
Gary 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 When
FITC
 
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.js
orkaplan
 
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
Stuart (Pid) Williams
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
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 & Mobile
Amazon 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.js
Chris 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 Applications
Ohad Kravchick
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
Gonzalo 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.js
Richard 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
 

Similar to 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
 

Recently uploaded

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 

Recently uploaded (20)

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 

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. ?

Editor's Notes

  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