Tane Piper - @tanepiper
An Introduction To
http://nodejs.org
  
What Is Node?
nodejs (node) is a set of bindings to the V8
javascript VM. They allow developers to script
programs usin...
  
Features of Node
 Node is similar to
 Ruby's Event Machine
 Python's Twisted
 Node takes the event model a bit furt...
  
Synchronous vs Asyncronous
$query="SELECT * FROM contacts";
$result=mysql_query($query);
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­...
  
What is the software doing?
  
x
http://www.flickr.com/photos/nationaalarchief/3675431410/
What is the software doing?
 It's Waiting –
Wasting cycles
  
Synchronous vs Asyncronous
db.query(”SELECT * FROM contacts”, function(err, rows) {
rows.forEach(function(row) {
consol...
  
A HTTP Server in 4 lines
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Con...
  
EventEmitter – The powerhouse
of node
This should look familiar to most of you:
jQuery('.foo').click(function() {
var f...
  
EventEmitter – The powerhouse
of node
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter...
  
EventEmitter – A I/O Example
var spawn = require('child_process').spawn,
    ls    = spawn('ls', ['­lh', '/usr']);
ls.s...
  
NPM – Node Package Manager
https://github.com/isaacs/npm
Used to install and publish your node programs.
JSON package f...
  
ExpressJS – Nodejs-powered
framework
npm install express
Robust routing
Redirection helpers
Dynamic view helpers
Applic...
  
ExpressJS - Example
Var express = require('express');
var app = express.createServer();
app.get('/', function(req, res,...
  
Something new: node-canvas
var Canvas = require('canvas')
  , canvas = new Canvas(200,200)
  , ctx = canvas.getContext(...
  
Something new: node-canvas
  
nodejs Community
Google Groups:
nodejs – General Community
nodejs-dev – Low level development
https://github.com/ry/nod...
  
Thank You
Any Questions?
Upcoming SlideShare
Loading in...5
×

@techmeetup Edinburgh nodejs talk

2,156

Published on

My nodejs presentation given on 10th November 2010

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,156
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
36
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

@techmeetup Edinburgh nodejs talk

  1. 1.    Tane Piper - @tanepiper An Introduction To http://nodejs.org
  2. 2.    What Is Node? nodejs (node) is a set of bindings to the V8 javascript VM. They allow developers to script programs using asynchronous I/O in javascript. Focused on performance and memory useage through an event loop – not threads.
  3. 3.    Features of Node  Node is similar to  Ruby's Event Machine  Python's Twisted  Node takes the event model a bit further—it presents the event loop as a language construct instead of as a library.  Node simply enters the event loop after executing the input script. Node exits the event loop when there are no more callbacks to perform
  4. 4.    Synchronous vs Asyncronous $query="SELECT * FROM contacts"; $result=mysql_query($query); ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ File file = new File("C:MyFile.txt"); fis = new FileInputStream(file); fis.close();
  5. 5.    What is the software doing?
  6. 6.    x http://www.flickr.com/photos/nationaalarchief/3675431410/ What is the software doing?  It's Waiting – Wasting cycles
  7. 7.    Synchronous vs Asyncronous db.query(”SELECT * FROM contacts”, function(err, rows) { rows.forEach(function(row) { console.log(row); }); }); ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ fs.readFile('techmeetup.txt', function(data) { console.log(data); }); doSomethingElseWhileNotWaiting();
  8. 8.    A HTTP Server in 4 lines var http = require('http'); http.createServer(function (req, res) {   res.writeHead(200, {'Content­Type': 'text/plain'});   res.end('Hello Worldn'); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/');
  9. 9.    EventEmitter – The powerhouse of node This should look familiar to most of you: jQuery('.foo').click(function() { var foo = this.attr('rel'); });
  10. 10.    EventEmitter – The powerhouse of node var EventEmitter = require('events').EventEmitter; var emitter = new EventEmitter; emitter.on('name', function(data){     console.log(data + ' rocks'); }); emitter.emit('name', 'nodejs'); emitter.emit('name', 'techmeetup');
  11. 11.    EventEmitter – A I/O Example var spawn = require('child_process').spawn,     ls    = spawn('ls', ['­lh', '/usr']); ls.stdout.on('data', function (data) {   console.log('stdout: ' + data); }); ls.stderr.on('data', function (data) {   console.log('stderr: ' + data); }); ls.on('exit', function (code) {   console.log('child proc exited with code ' + code); });
  12. 12.    NPM – Node Package Manager https://github.com/isaacs/npm Used to install and publish your node programs. JSON package format that It manages dependencies. Integrates nicely with man pages
  13. 13.    ExpressJS – Nodejs-powered framework npm install express Robust routing Redirection helpers Dynamic view helpers Application level view options Content negotiation Focus on high performance View rendering and partials support Environment based configuration Session based flash notifications
  14. 14.    ExpressJS - Example Var express = require('express'); var app = express.createServer(); app.get('/', function(req, res, next){     res.send('Hello World'); }); app.post('/:name', function(req, res, next) { var name = req.params.name;    If (!name) {      next(new Error('No name passed');    } else {      res.send(['Hello', name].join(' '));    } }); app.listen(3000);
  15. 15.    Something new: node-canvas var Canvas = require('canvas')   , canvas = new Canvas(200,200)   , ctx = canvas.getContext('2d'); var fs = require('fs')   , out = fs.createWriteStream(__dirname + '/text.png')   , stream = canvas.createPNGStream(); ctx.font = '30px Droid Sans'; ctx.rotate(.1); ctx.fillText("Yay Techmeet Edinburgh!", 50, 100); stream.on('data', function(chunk){   out.write(chunk); }); stream.on('end', function(){   console.log('saved png'); });
  16. 16.    Something new: node-canvas
  17. 17.    nodejs Community Google Groups: nodejs – General Community nodejs-dev – Low level development https://github.com/ry/node/wiki/modules
  18. 18.    Thank You Any Questions?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×