0
Building                    businesspost.ie                    Richard Rodger                    @rjrodgerFriday 9 Novembe...
businesspost.ieFriday 9 November 2012
Everything                    JavaScript.Friday 9 November 2012
So, how do you       build it?       ‣have a common code-base,       ‣be service-oriented,       ‣use small, independent p...
Web                 Mobile                     Cloud                              Services                Web Apps        ...
Client-side                         Router   #! URLs                                                    • Common code-base...
Running...               1. Load               static       2. Init shared               index.html   code, then       3. ...
Native Apps    Same code as mobile web versions, ...     ... wrapped using PhoneGap to run natively     ... plus some nati...
Server-side                                  map /api/ URLs       • nginx & Node.js                         Router        ...
Running...               1. Connect               to databases   2. Route               and listen     HTTP            3. ...
Callback Style         this is the common language of         Node.js - always use it!         doSomething( input, functio...
Error Pattern         use functional style avoid         if statements everywhere         function wraperror( success ) { ...
Cloud Services                 Database        Hosting    Monitors                  MongoDB        Amazon      Amazon     ...
Integrations...    JSON, XML, simple form data, text files, ...      ... all easy using JavaScript and Node.js Modules     ...
Lots of Little                    Processes                    ‣Web API       ‣Admin site                    ‣RSS reader ‣...
Use queues!                    This is how                    processes talk.Friday 9 November 2012
Example!         news reader finds an image...         ... and pushes it onto queue         redis.publish("images", "/stor...
Node.js                    modules.Friday 9 November 2012
Write small                    modules,                    not big apps!Friday 9 November 2012
businesspost.ie                    modules                    ‣underscore,                    ‣connect,                   ...
underscore            module            ‣npm install underscore            ‣underscorejs.org            ‣do functional pro...
connect            module            ‣npm install connect            ‣senchalabs.org/connect            ‣build web service...
express            module            ‣npm install express            ‣expressjs.com            ‣build websites            ...
appgen            module            ‣npm install appgen            ‣appgenjs.org            ‣build multi-platform web apps...
seneca            module            ‣npm install seneca            ‣senecajs.org            ‣build business logic         ...
businesspost.ie                    lessons.Friday 9 November 2012
Lesson:Friday 9 November 2012
Lesson:                                    code volume                  4                  3                  2           ...
Lesson:    multi-platform client-side JavaScript is really hard        • a framework is a must           • code against EC...
Lesson:    multi-platform HTML/CSS is really hard        • "structured" CSS is a must   • Clean, semantic HTML is not     ...
Lesson:    the app stores are not web sites        • that bug in version one... • you cant deploy hot fixes         • will ...
Lesson:    Node.js is awesome!        • High performance             • callback spaghetti is not a                        ...
Lesson:    Small processes can save your life        • Prevents total failure even if                other systems fail   ...
Thank You!                    Richard Rodger                    @rjrodgerFriday 9 November 2012
Upcoming SlideShare
Loading in...5
×

Building businesspost.ie using Node.js

1,438

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,438
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Building businesspost.ie using Node.js"

  1. 1. Building businesspost.ie Richard Rodger @rjrodgerFriday 9 November 2012
  2. 2. businesspost.ieFriday 9 November 2012
  3. 3. Everything JavaScript.Friday 9 November 2012
  4. 4. So, how do you build it? ‣have a common code-base, ‣be service-oriented, ‣use small, independent pieces.Friday 9 November 2012
  5. 5. Web Mobile Cloud Services Web Apps Services API Mobile & REST & Database Tablet Web JSON Mobile & Horizontal Third Party Tablet Apps Scale Services Desktop Cloud Monitoring Web HostedFriday 9 November 2012
  6. 6. Client-side Router #! URLs • Common code-base • even for hybrid apps! Models Data, biz logic • backbone.js • shims for weak browsers Views DOM Layout • browser-targeting: user- agent & capabilities • responsive layout (mostly) Helpers Shared codeFriday 9 November 2012
  7. 7. Running... 1. Load static 2. Init shared index.html code, then 3. Init and assets targeted router, and 4. Wait for code display as events per #! URLFriday 9 November 2012
  8. 8. Native Apps Same code as mobile web versions, ... ... wrapped using PhoneGap to run natively ... plus some native pluginsFriday 9 November 2012
  9. 9. Server-side map /api/ URLs • nginx & Node.js Router to functions • Small code volume API function( req, • Third party modules: functions res ) { ... } • connect Shared code • express Helpers (some with client) • seneca Open source • Deploy with: Modules heavy-lifting • sudo killall nodeFriday 9 November 2012
  10. 10. Running... 1. Connect to databases 2. Route and listen HTTP 3. Talk to for HTTP requests to database, 4. Send API functions wait for JSON back callback to clientFriday 9 November 2012
  11. 11. Callback Style this is the common language of Node.js - always use it! doSomething( input, function( error, output ) { ... })Friday 9 November 2012
  12. 12. Error Pattern use functional style avoid if statements everywhere function wraperror( success ) { return function( err, result ) { if( err ) return handleError( err ); else return success( result ); } } database.doQuery( wraperror( function( result ) { doRealWork( result ); }))Friday 9 November 2012
  13. 13. Cloud Services Database Hosting Monitors MongoDB Amazon Amazon Load Redis cloudkick Balancer Instance memcached Continuous ScalingFriday 9 November 2012
  14. 14. Integrations... JSON, XML, simple form data, text files, ... ... all easy using JavaScript and Node.js Modules Analytics Twitter E-Commerce In-App Logging Facebook Purchasing Email LinkedIn Stock FeedFriday 9 November 2012
  15. 15. Lots of Little Processes ‣Web API ‣Admin site ‣RSS reader ‣Search index ‣Image resizer ‣SitemapFriday 9 November 2012
  16. 16. Use queues! This is how processes talk.Friday 9 November 2012
  17. 17. Example! news reader finds an image... ... and pushes it onto queue redis.publish("images", "/storage/img1234.jpg"); then image processor resizes... redis.subscribe("images"); redis.on("message", function(channel, message) { resizeImage( message ) // message == "/storage/img1234.jpg" });Friday 9 November 2012
  18. 18. Node.js modules.Friday 9 November 2012
  19. 19. Write small modules, not big apps!Friday 9 November 2012
  20. 20. businesspost.ie modules ‣underscore, ‣connect, ‣express, ‣appgen, ‣senecaFriday 9 November 2012
  21. 21. underscore module ‣npm install underscore ‣underscorejs.org ‣do functional programming ‣provides "missing" JS features ‣useful for handling arrays, objectsFriday 9 November 2012
  22. 22. connect module ‣npm install connect ‣senchalabs.org/connect ‣build web services ‣provides "middleware" pattern ‣useful for HTTP request handlingFriday 9 November 2012
  23. 23. express module ‣npm install express ‣expressjs.com ‣build websites ‣provides HTML page handling ‣useful for building dynamic sitesFriday 9 November 2012
  24. 24. appgen module ‣npm install appgen ‣appgenjs.org ‣build multi-platform web apps ‣generates multiple code versions ‣useful for organizing platform codeFriday 9 November 2012
  25. 25. seneca module ‣npm install seneca ‣senecajs.org ‣build business logic ‣provides "command" pattern ‣useful for organizing featuresFriday 9 November 2012
  26. 26. businesspost.ie lessons.Friday 9 November 2012
  27. 27. Lesson:Friday 9 November 2012
  28. 28. Lesson: code volume 4 3 2 1 0 Client JavaScript Server JavaScriptFriday 9 November 2012
  29. 29. Lesson: multi-platform client-side JavaScript is really hard • a framework is a must • code against ECMA, use shims to support older browsers • backbone.js • Code/Test/Debug inside Safari • business logic must be in • phonegap.github.com/weinre for common code hard to reach places • browser-specific code • use error capture in production • virtual .js files • Finally, use a simple static site as a fallback (also for Googlebot) • use jshint to keep IE happy • appgen module helps!Friday 9 November 2012
  30. 30. Lesson: multi-platform HTML/CSS is really hard • "structured" CSS is a must • Clean, semantic HTML is not optional • sass or less • graceful degradation may • Be happy with require radically different CSS • 100% "Responsive" design is tough • media queries • Responsive within browser • CSS3 transforms subsets has higher reward/effort • browser-specific code •appgen module helps! • virtual .css filesFriday 9 November 2012
  31. 31. Lesson: the app stores are not web sites • that bug in version one... • you cant deploy hot fixes • will take two weeks to • make everything fix via an update configurable! • some users will never • All prices, text, host update names, urls, ... • appears after an OS • On launch, app "checks-in" update for new configuration • this will save your lifeFriday 9 November 2012
  32. 32. Lesson: Node.js is awesome! • High performance • callback spaghetti is not a problem in practice • High throughput • Low CPU usage • use functional style • Constant memory usage • client-side code is far more difficult • leaks will kill, but then • < 100ms startup time • Dont do CPU intensive stuff • means you may not notice! • Node.js is not for thatFriday 9 November 2012
  33. 33. Lesson: Small processes can save your life • Prevents total failure even if other systems fail • Memory leaks are not a disaster - just restart! • Easy to scale - just move to • Use queues in new machines preference to direct • Easy to code - you get small, communication single purpose code bases • Easy to manage - even • Easy to divide up work traditional process between developers management will get you a long wayFriday 9 November 2012
  34. 34. Thank You! Richard Rodger @rjrodgerFriday 9 November 2012
  1. A particular slide catching your eye?

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

×