SlideShare a Scribd company logo
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 fired. But there can only be one
callback firing at the same time. Until that callback has
finished 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 fire." 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 file 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 defined.

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

More Related Content

PDF
Running JavaScript Efficiently in a Java World
PPTX
What is Node.js
PPTX
Future of NodeJS
PPT
Introduction to node.js aka NodeJS
PPTX
Intro to Node.js (v1)
PPTX
Websockets and SockJS, Real time chatting
PDF
Complete MVC on NodeJS
PPTX
NodeJS - Server Side JS
Running JavaScript Efficiently in a Java World
What is Node.js
Future of NodeJS
Introduction to node.js aka NodeJS
Intro to Node.js (v1)
Websockets and SockJS, Real time chatting
Complete MVC on NodeJS
NodeJS - Server Side JS

What's hot (20)

PDF
Understanding the Single Thread Event Loop
PDF
Basic Understanding and Implement of Node.js
PPTX
Node.js debugging
PDF
Comet with node.js and V8
PDF
Meteorjs - Futuristic web framework
PPTX
Node js Introduction
PPTX
Node.js tutoria for beginner
PPTX
Introduction to node.js by jiban
PDF
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
PDF
Testando JavaScript com Spock
PPTX
Create Rest API in Nodejs
PDF
Full stack, Full run, Full test
PPTX
Node js training (1)
PDF
NodeJS ecosystem
PPTX
Introduction to node.js GDD
PDF
Node.js for beginner
PDF
WebSockets with Spring 4
PDF
Going Node At Netflix
PPTX
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
KEY
Servers with Event Machine - David Troy - RailsConf 2011
Understanding the Single Thread Event Loop
Basic Understanding and Implement of Node.js
Node.js debugging
Comet with node.js and V8
Meteorjs - Futuristic web framework
Node js Introduction
Node.js tutoria for beginner
Introduction to node.js by jiban
Meetup RomaJS - introduzione interattiva a Node.js - Luca Lanziani - Codemoti...
Testando JavaScript com Spock
Create Rest API in Nodejs
Full stack, Full run, Full test
Node js training (1)
NodeJS ecosystem
Introduction to node.js GDD
Node.js for beginner
WebSockets with Spring 4
Going Node At Netflix
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
Servers with Event Machine - David Troy - RailsConf 2011
Ad

Viewers also liked (8)

PDF
A preliminary study of node js
PDF
Node.js for Rubists
KEY
Node.js Presentation Rotterdam.PHP
PPTX
Intro2 nodejs 2pm
PPTX
A slightly advanced introduction to node.js
KEY
Dcjq node.js presentation
PDF
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
PPTX
Project CHIP Almere - De patient als portaal
A preliminary study of node js
Node.js for Rubists
Node.js Presentation Rotterdam.PHP
Intro2 nodejs 2pm
A slightly advanced introduction to node.js
Dcjq node.js presentation
Becoming a Node.js Ninja on Cloud Foundry - Open Tour London
Project CHIP Almere - De patient als portaal
Ad

Similar to Introduction to Node.js (20)

PPTX
PPTX
Introduction to Node.js
ODP
Introduce about Nodejs - duyetdev.com
PDF
NodeJS for Beginner
PPTX
Introduction to node.js By Ahmed Assaf
PPT
Nodejs Intro Part One
PDF
FITC - Node.js 101
PPTX
An overview of node.js
PDF
Nodejs - A-quick-tour-v3
PDF
Node.js 101 with Rami Sayar
PDF
Node.js introduction
KEY
Node.js - A practical introduction (v2)
PPTX
Kalp Corporate Node JS Perfect Guide
DOCX
unit 2 of Full stack web development subject
PPTX
Introduction to Node (15th May 2017)
PPTX
introduction to node.js
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
PPT
Node js beginner
PPTX
Node js meetup
PPT
18_Node.js.ppt
Introduction to Node.js
Introduce about Nodejs - duyetdev.com
NodeJS for Beginner
Introduction to node.js By Ahmed Assaf
Nodejs Intro Part One
FITC - Node.js 101
An overview of node.js
Nodejs - A-quick-tour-v3
Node.js 101 with Rami Sayar
Node.js introduction
Node.js - A practical introduction (v2)
Kalp Corporate Node JS Perfect Guide
unit 2 of Full stack web development subject
Introduction to Node (15th May 2017)
introduction to node.js
Server Side Web Development Unit 1 of Nodejs.pptx
Node js beginner
Node js meetup
18_Node.js.ppt

More from Jack Franklin (6)

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

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Hybrid model detection and classification of lung cancer
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Unlocking AI with Model Context Protocol (MCP)
Accuracy of neural networks in brain wave diagnosis of schizophrenia
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
WOOl fibre morphology and structure.pdf for textiles
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Getting Started with Data Integration: FME Form 101
Heart disease approach using modified random forest and particle swarm optimi...
Web App vs Mobile App What Should You Build First.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
TLE Review Electricity (Electricity).pptx
cloud_computing_Infrastucture_as_cloud_p
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25-Week II
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
OMC Textile Division Presentation 2021.pptx
Approach and Philosophy of On baking technology
Hybrid model detection and classification of lung cancer
1 - Historical Antecedents, Social Consideration.pdf
MIND Revenue Release Quarter 2 2025 Press Release

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 fired. But there can only be one callback firing at the same time. Until that callback has finished 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 fire." 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 file 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 defined. 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