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

Like this? Share it with your network

Share

Javascript Everywhere From Nose To Tail

on

  • 8,010 views

 

Statistics

Views

Total Views
8,010
Views on SlideShare
6,903
Embed Views
1,107

Actions

Likes
1
Downloads
49
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 Presentation Transcript

  • 1. JavaScript Everywhere From Nose To Tail Carl Husselbee - SensisCliffano Subagio (@cliffano) - Shine Technologies
  • 2. Citysearch.com.au
  • 3. New Platform Improved application performance Better memory usage Improved content publishing reliability Zero content duplication Improved user experience(project is still ongoing...)
  • 4. The Three Amigos + +
  • 5. One JavaScript To Rule Them All
  • 6. In A Nutshell
  • 7. CouchDB Document oriented Schema free Design document in JavaScript Incremental replication HTTP API
  • 8. 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
  • 9. 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"
  • 10. 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
  • 11. CradleCouchDB client for Node.jsUses CouchDB REST APIAsynchronousBuilt-in caching
  • 12. Node.js Server-side JavaScript Based on V8 Single Threaded Non-blocking I/O
  • 13. Single ThreadedNo more thread deadlockMore predictable app server memory usageLike Nginx vs Apache
  • 14. 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
  • 15. The Callback Trap
  • 16. 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);
  • 17. 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
  • 18. Async In A LoopThis looks innocentfor (var i = 0; i < 1000000; i++) { console.log(Meditate on this, you must!);}
  • 19. Async In A Loopconsole.log is asynchronousNode.js is faster than terminal display
  • 20. Library ChangesWithin the past one year: Homegrown web framework >> Express node-couch >> Cradle Various template engines >> Jazz Promises >> Callbacks + Async
  • 21. TestingInsanely fast even on slow PC15,000 SLOC100% test coverage34 secondsYUITest, JSCoverage, nodelint
  • 22. 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
  • 23. More Homegrown ModulesLog4js-node - logging frameworkSeverity level and rolling log fileCouchtato - CouchDB document utility toolDoesn’t require CouchDB design doc knowledge
  • 24. Continuous Integration Jenkins Node.js Plugin Nestor - Jenkins Node.js CLI
  • 25. Conclusion CouchDB rocks! Node.js rocks! JavaScript web stack rocks!
  • 26. Questions?
  • 27. 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
  • 28. 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/