Javascript Everywhere From Nose To Tail
Upcoming SlideShare
Loading in...5
×
 

Javascript Everywhere From Nose To Tail

on

  • 7,917 views

 

Statistics

Views

Total Views
7,917
Views on SlideShare
6,810
Embed Views
1,107

Actions

Likes
1
Downloads
46
Comments
0

10 Embeds 1,107

http://blog.cliffano.com 1038
http://www.redditmedia.com 37
http://feeds.feedburner.com 13
http://twitter.com 8
https://twitter.com 5
http://a0.twimg.com 2
http://www.linkedin.com 1
http://cliffano.wordpress.com 1
http://webcache.googleusercontent.com 1
https://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Javascript Everywhere From Nose To Tail Javascript Everywhere From Nose To Tail Presentation Transcript

  • JavaScript Everywhere From Nose To Tail Carl Husselbee - SensisCliffano Subagio (@cliffano) - Shine Technologies
  • Citysearch.com.au
  • New Platform Improved application performance Better memory usage Improved content publishing reliability Zero content duplication Improved user experience(project is still ongoing...)
  • The Three Amigos + +
  • One JavaScript To Rule Them All
  • In A Nutshell
  • CouchDB Document oriented Schema free Design document in JavaScript Incremental replication HTTP API
  • DocumentSimply a JSON object{ "_id": "listing-123", "_rev": "D1C946B7", "business_name": "Wolfgang Puck", "desc": "Fine dining and casual dining...", "rating": 5, "city": "Melbourne"}Stays as JSON on all layers
  • Replication Content publishing - replication rule curl -X POST "http://host/_replicate" -d {"source": "db-src", "target": "db-target", "continuous": true} -H "Content-Type: application/json" Content indexing - continuous changes feed curl -X GET "http://host/db/_changes?feed=continuous&since=123"
  • Design DocumentA simple map reduce"views": { "melbourne_rating": { "map": function (doc) { if (doc.city === Melbourne) { emit(null, doc.rating); } }, "reduce": function (key, values, rereduce) { return sum(values); }}}Highly testableEasy to mock up
  • CradleCouchDB client for Node.jsUses CouchDB REST APIAsynchronousBuilt-in caching
  • Node.js Server-side JavaScript Based on V8 Single Threaded Non-blocking I/O
  • Single ThreadedNo more thread deadlockMore predictable app server memory usageLike Nginx vs Apache
  • Non-blocking I/OI/O is expensiveTraditional web app wastes time on I/O // blocking // non-blocking var listings = db.getListings(); var callback = function render(listings); (listings) { render(listings); } db.getListings(callback);Node.js provides non-blocking API
  • The Callback Trap
  • Nested Callbacksvar util = require(‘util’), listingId = listing-123;function commentsCb(err, result) { if (err) { } else { console.log(Comments: + util.inspect(result)); }}function listingCb(err, result) { if (err) { } else { console.log(Listing: + util.inspect(result)); db.getComments(listingId, commentsCb) }}db.getListing(listingId, listingCb);
  • A Better WayUse control flow modulevar async = require(async), listingId = listing-123;function getComments(cb) { db.getComments(listingId, cb);}function getListing(cb) { db.getListing(listingId, cb);}async.parallel({ comments: getComments, listing: getListing },function (err, results) { // results gives { listing: listingResult, comments: commentsResult }});Lots of other solutions: TameJS, Step, Seq, etc
  • Async In A LoopThis looks innocentfor (var i = 0; i < 1000000; i++) { console.log(Meditate on this, you must!);}
  • Async In A Loopconsole.log is asynchronousNode.js is faster than terminal display
  • Library ChangesWithin the past one year: Homegrown web framework >> Express node-couch >> Cradle Various template engines >> Jazz Promises >> Callbacks + Async
  • TestingInsanely fast even on slow PC15,000 SLOC100% test coverage34 secondsYUITest, JSCoverage, nodelint
  • Homegrown ModulesJazz - template engine{foreach doc in widget.docs} {if (doc.type eq video)} <span><a href="{doc.videourl}">{doc.title}</a></span> {else} <a href="{helper.createUrl(doc.key)}"> <h3>{doc.title}</h3> </a> {end}{end}No business logicSynchronous compilation, asynchronous evalua
  • More Homegrown ModulesLog4js-node - logging frameworkSeverity level and rolling log fileCouchtato - CouchDB document utility toolDoesn’t require CouchDB design doc knowledge
  • Continuous Integration Jenkins Node.js Plugin Nestor - Jenkins Node.js CLI
  • Conclusion CouchDB rocks! Node.js rocks! JavaScript web stack rocks!
  • Questions?
  • ResourcesCouchDB - http://couchdb.apache.orgNode.js - http://nodejs.orgJazz - http://github.com/shinetech/jazzlog4js-node - http://github.com/csausdev/log4js-nodeCouchtato - http://github.com/cliffano/couchtatoJenkins Node.js Plugin - https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+PluginNestor - http://github.com/cliffano/nestor
  • Credits http://www.flickr.com/photos/daveaustria/2654190796/ by Dave Austria http://www.flickr.com/photos/38485387@N02/3580728177/ by flickrfavorites http://www.housecontainer.nl/blog/about-me/127-dj-yoda-from-star-wars.html http://www.miccicohan.net/blog/studio-antics-and-of-coursethe-rolling-stones/