• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to Node.js
 

Introduction to Node.js

on

  • 1,197 views

A quick talk I did at London Titanium meet up introducting Node.js

A quick talk I did at London Titanium meet up introducting Node.js

Statistics

Views

Total Views
1,197
Views on SlideShare
1,169
Embed Views
28

Actions

Likes
0
Downloads
8
Comments
0

5 Embeds 28

http://lanyrd.com 16
http://nodeslide.herokuapp.com 7
https://twimg0-a.akamaihd.net 3
https://si0.twimg.com 1
https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via SlideShare as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to Node.js Introduction to Node.js Presentation Transcript

    • Introduction to Node.js
    • WhoDeveloper for Kainos (Java, Scala, Rails, JavaScript, HTML,CSS)Student at University of BathWrite a lot about JavaScript atwww.javascriptplayground.com@Jack_Franklin on Twitter
    • Origins of NodeServer side JavaScript done rightruns on Chromes V8 Engine (its quick)Evented I/O - runs single non-blocking thread with eventloopthis is great as JS was designed to be run in a single threadenvironment (browser)
    • Node right nowV0.8 standardised the API (non breaking)currently V0.8.4, much more stable than < 0.8Install via installers, from source or via package manager likeBrew.
    • NPMPackage Manager for Node (think rubygems / bundler forNode)Full of really useful modules (and some less useful ones)12,627 packages as of yesterday (browse athttp://search.npmjs.org/)
    • Event Driven JavaScriptLearn to think Asynchronously "Once node has completed atask, the callback for it is fired. But there can only be onecallback firing at the same time. Until that callback hasfinished executing, all other callbacks have to wait in line. Inaddition to that, there is no guarantee on the order in whichthe callbacks will fire." From: http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cbRelated: Async.js https://github.com/caolan/async/
    • Callbacks Lots and lots of callbacksvar 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 assemblethem into other modules that do a bigger thing. You cant getinto callback hell if you dont go there." Isaac Schlueter -Node.js core contributor @izswrite your code in a file like normal://file socket-module.jsfunction writeResponse(socket) {socket.write(Echo serverrn);socket.pipe(socket);});
    • module.exports = {resp: writeResponse}(this follows the CommonJS module structure)require and use itvar net = require(net);var socketModule = require(socket-module);var server = net.createServer(socketModule.resp);server.listen(1337, 127.0.0.1);
    • Databases with NodeRedis & the Redis NPM Package is awesomeAdapters for all common DB solutions
    • Web FrameworksMost popular is Express JS - www.expressjs.comLoads out there - Google "node js framework"Geddy, Flatiron, RailwayJSTools like this are slowly but surely maturing
    • Expressvar 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 TestingNodeUnit https://github.com/caolan/nodeunitMocha http://visionmedia.github.com/mocha/Lots more. Find one that suits (I love Mocha)
    • In the wildJSBin by @rem - www.jsbin.com - pure awesomenessTweetDig by @mheap - www.tweetdig.com - 2.5m tweets perday
    • To Sum UpNode is still very young, although standards and conventionsare 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.comCodeSchool Node course www.codeschool.comAsync JavaScript book from Trevor Burnhanwww.leanpub.com/asyncjsHow to Node blog www.howtonode.org/
    • Any Questions?Slides on Github: gist.github.com/jackfranklinwww.javascriptplayground.com for JavaScript tutorials(including Node)@Jack_Franklin if you can put up with even more of merambling