SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
Introduction to Node.js
Who
Developer for Kainos (Java, Scala, Rails, JavaScript, HTML,
CSS)

Student at University of Bath

Write a lot about JavaScript at
www.javascriptplayground.com

@Jack_Franklin on Twitter
Origins of Node
Server side JavaScript done right

runs on Chrome's V8 Engine (it's quick)

Evented I/O - runs single non-blocking thread with event
loop

this is great as JS was designed to be run in a single thread
environment (browser)
Node right now
V0.8 standardised the API (non breaking)

currently V0.8.4, much more stable than < 0.8

Install via installers, from source or via package manager like
Brew.
NPM
Package Manager for Node (think rubygems / bundler for
Node)

Full of really useful modules (and some less useful ones)

12,627 packages as of yesterday (browse at
http://search.npmjs.org/)
Event Driven JavaScript
Learn to think Asynchronously "Once node has completed a
task, the callback for it is ïŹred. But there can only be one
callback ïŹring at the same time. Until that callback has
ïŹnished executing, all other callbacks have to wait in line. In
addition to that, there is no guarantee on the order in which
the callbacks will ïŹre." From: http://debuggable.com/posts
/understanding-node-js:4bd98440-45e4-4a9a-
8ef7-0f7ecbdd56cb

Related: Async.js https://github.com/caolan/async/
Callbacks
  Lots and lots of callbacks

var net = require('net');



var server = net.createServer(function (socket) {

  socket.write('Echo serverrn');

  socket.pipe(socket);

});



server.listen(1337, '127.0.0.1');



  How to avoid: http://callbackhell.com/
Naming your Callbacks
  Did you know you can name them?

var net = require('net');

var server = net.createServer(function writeResponse(socket) {

  socket.write('Echo serverrn');

  socket.pipe(socket);

});

server.listen(1337, '127.0.0.1');
Avoiding Callbacks: Modules
"Write small modules that each do one thing, and assemble
them into other modules that do a bigger thing. You can't get
into callback hell if you don't go there." Isaac Schlueter -
Node.js core contributor @izs

write your code in a ïŹle like normal:
//file socket-module.js

function writeResponse(socket) {

socket.write('Echo serverrn');

socket.pipe(socket);

});
module.exports = {

resp: writeResponse

}


(this follows the CommonJS module structure)

require and use it
var net = require('net');

var socketModule = require('socket-module');

var server = net.createServer(socketModule.resp);

server.listen(1337, '127.0.0.1');
Databases with Node
Redis & the Redis NPM Package is awesome

Adapters for all common DB solutions
Web Frameworks
Most popular is Express JS - www.expressjs.com

Loads out there - Google "node js framework"

Geddy, Flatiron, RailwayJS

Tools like this are slowly but surely maturing
Express
var app = express.createServer();



app.get('/', function(req, res){

      res.send('Hello World');

});



app.listen(3000);



  routing, views (Jade), etc

  very extensible
About to hit V3
Unit Testing
NodeUnit https://github.com/caolan/nodeunit

Mocha http://visionmedia.github.com/mocha/

Lots more. Find one that suits (I love Mocha)
In the wild
JSBin by @rem - www.jsbin.com - pure awesomeness

TweetDig by @mheap - www.tweetdig.com - 2.5m tweets per
day
To Sum Up
Node is still very young, although standards and conventions
are beginning to be deïŹned.

Lack of resources is slowly becoming less of an issue.

V0.8 is huge improvement on prior versions.

Node is seriously quick if used properly.
Further Resources
@Peepcode screencasts www.peepcode.com

CodeSchool Node course www.codeschool.com

Async JavaScript book from Trevor Burnhan
www.leanpub.com/asyncjs

How to Node blog www.howtonode.org/
Any Questions?
Slides on Github: gist.github.com/jackfranklin

www.javascriptplayground.com for JavaScript tutorials
(including Node)

@Jack_Franklin if you can put up with even more of me
rambling
Introduction to Node.js

Weitere Àhnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Understanding the Single Thread Event Loop
Understanding the Single Thread Event LoopUnderstanding the Single Thread Event Loop
Understanding the Single Thread Event Loop
 
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
 
Node.js debugging
Node.js debuggingNode.js debugging
Node.js debugging
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Meteorjs - Futuristic web framework
Meteorjs - Futuristic web frameworkMeteorjs - Futuristic web framework
Meteorjs - Futuristic web framework
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Node.js tutoria for beginner
Node.js tutoria for beginnerNode.js tutoria for beginner
Node.js tutoria for beginner
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
 
Testando JavaScript com Spock
Testando JavaScript com SpockTestando JavaScript com Spock
Testando JavaScript com Spock
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
Full stack, Full run, Full test
Full stack, Full run, Full testFull stack, Full run, Full test
Full stack, Full run, Full test
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Node.js for beginner
Node.js for beginnerNode.js for beginner
Node.js for beginner
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
 
Going Node At Netflix
Going Node At NetflixGoing Node At Netflix
Going Node At Netflix
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
 
Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011
 

Andere mochten auch (8)

A preliminary study of node js
A preliminary study of node jsA preliminary study of node js
A preliminary study of node js
 
Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for Rubists
 
Node.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHPNode.js Presentation Rotterdam.PHP
Node.js Presentation Rotterdam.PHP
 
Intro2 nodejs 2pm
Intro2 nodejs 2pmIntro2 nodejs 2pm
Intro2 nodejs 2pm
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.js
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
 
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour LondonBecoming a Node.js Ninja on Cloud Foundry - Open Tour London
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
 
Project CHIP Almere - De patient als portaal
Project CHIP Almere - De patient als portaalProject CHIP Almere - De patient als portaal
Project CHIP Almere - De patient als portaal
 

Ähnlich wie Introduction to Node.js

Why Node.js
Why Node.jsWhy Node.js
Why Node.js
guileen
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 

Ähnlich wie Introduction to Node.js (20)

Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
Node.js vs Play Framework
Node.js vs Play FrameworkNode.js vs Play Framework
Node.js vs Play Framework
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebAppsIBM InterConnect: Java vs JavaScript for Enterprise WebApps
IBM InterConnect: Java vs JavaScript for Enterprise WebApps
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
D. Andreadis, Red Hat: Concepts and technical overview of Quarkus
D. Andreadis, Red Hat: Concepts and technical overview of QuarkusD. Andreadis, Red Hat: Concepts and technical overview of Quarkus
D. Andreadis, Red Hat: Concepts and technical overview of Quarkus
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Serverless Java on Kubernetes
Serverless Java on KubernetesServerless Java on Kubernetes
Serverless Java on Kubernetes
 
Node js
Node jsNode js
Node js
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 

Mehr von Jack Franklin (6)

Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
 
Introduction to jQuery at Barcamp London 8
Introduction to jQuery at Barcamp London 8Introduction to jQuery at Barcamp London 8
Introduction to jQuery at Barcamp London 8
 
jQuery Tips & Tricks - Bath Camp 2010
jQuery Tips & Tricks - Bath Camp 2010jQuery Tips & Tricks - Bath Camp 2010
jQuery Tips & Tricks - Bath Camp 2010
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
 
Designing for the Teenage Market
Designing for the Teenage MarketDesigning for the Teenage Market
Designing for the Teenage Market
 

KĂŒrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

KĂŒrzlich hochgeladen (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Introduction to Node.js

  • 2. Who Developer for Kainos (Java, Scala, Rails, JavaScript, HTML, CSS) Student at University of Bath Write a lot about JavaScript at www.javascriptplayground.com @Jack_Franklin on Twitter
  • 3. Origins of Node Server side JavaScript done right runs on Chrome's V8 Engine (it's quick) Evented I/O - runs single non-blocking thread with event loop this is great as JS was designed to be run in a single thread environment (browser)
  • 4. Node right now V0.8 standardised the API (non breaking) currently V0.8.4, much more stable than < 0.8 Install via installers, from source or via package manager like Brew.
  • 5. NPM Package Manager for Node (think rubygems / bundler for Node) Full of really useful modules (and some less useful ones) 12,627 packages as of yesterday (browse at http://search.npmjs.org/)
  • 6. Event Driven JavaScript Learn to think Asynchronously "Once node has completed a task, the callback for it is ïŹred. But there can only be one callback ïŹring at the same time. Until that callback has ïŹnished executing, all other callbacks have to wait in line. In addition to that, there is no guarantee on the order in which the callbacks will ïŹre." From: http://debuggable.com/posts /understanding-node-js:4bd98440-45e4-4a9a- 8ef7-0f7ecbdd56cb Related: Async.js https://github.com/caolan/async/
  • 7. Callbacks Lots and lots of callbacks var net = require('net'); var server = net.createServer(function (socket) { socket.write('Echo serverrn'); socket.pipe(socket); }); server.listen(1337, '127.0.0.1'); How to avoid: http://callbackhell.com/
  • 8. Naming your Callbacks Did you know you can name them? var net = require('net'); var server = net.createServer(function writeResponse(socket) { socket.write('Echo serverrn'); socket.pipe(socket); }); server.listen(1337, '127.0.0.1');
  • 9. Avoiding Callbacks: Modules "Write small modules that each do one thing, and assemble them into other modules that do a bigger thing. You can't get into callback hell if you don't go there." Isaac Schlueter - Node.js core contributor @izs write your code in a ïŹle like normal: //file socket-module.js function writeResponse(socket) { socket.write('Echo serverrn'); socket.pipe(socket); });
  • 10. module.exports = { resp: writeResponse } (this follows the CommonJS module structure) require and use it var net = require('net'); var socketModule = require('socket-module'); var server = net.createServer(socketModule.resp); server.listen(1337, '127.0.0.1');
  • 11. Databases with Node Redis & the Redis NPM Package is awesome Adapters for all common DB solutions
  • 12. Web Frameworks Most popular is Express JS - www.expressjs.com Loads out there - Google "node js framework" Geddy, Flatiron, RailwayJS Tools like this are slowly but surely maturing
  • 13. Express var app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000); routing, views (Jade), etc very extensible
  • 15. Unit Testing NodeUnit https://github.com/caolan/nodeunit Mocha http://visionmedia.github.com/mocha/ Lots more. Find one that suits (I love Mocha)
  • 16. In the wild JSBin by @rem - www.jsbin.com - pure awesomeness TweetDig by @mheap - www.tweetdig.com - 2.5m tweets per day
  • 17. To Sum Up Node is still very young, although standards and conventions are beginning to be deïŹned. Lack of resources is slowly becoming less of an issue. V0.8 is huge improvement on prior versions. Node is seriously quick if used properly.
  • 18. Further Resources @Peepcode screencasts www.peepcode.com CodeSchool Node course www.codeschool.com Async JavaScript book from Trevor Burnhan www.leanpub.com/asyncjs How to Node blog www.howtonode.org/
  • 19. Any Questions? Slides on Github: gist.github.com/jackfranklin www.javascriptplayground.com for JavaScript tutorials (including Node) @Jack_Franklin if you can put up with even more of me rambling