SlideShare une entreprise Scribd logo
1  sur  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
?

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Dernier (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

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

Notes de l'éditeur

  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