Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Moving from Node.js to Dart

Moving from Node.js to Dart

Faisal Abid explores how to take a production API built in Node.js and port it over to Dart.

You will learn about the differences between each platform for server-side APIs, and the challenges you will face when moving away from the Node platform to Dart.

Faisal goes over the advantages of developing in Dart and why it is the best bet for the future of server-side development.

Faisal Abid

April 28, 2015
Tweet

More Decks by Faisal Abid

Other Decks in Programming

Transcript

  1. WHAT YOU’LL LEARN Node.js or Dart Thinking in Dart Debugging

    Dart Deploying Dart @faisalabid +faisalabidx
  2. ABOUT ME Entrepreneur & Engineer Deployed many large scale Node.js

    API’s Written a handful of Dart web projects for clients Working in healthcare @ LEAGUE, during the day @faisalabid +faisalabidx
  3. THE BACKSTORY Market Wolf is a native Android application powered

    by a Dart API Originally was Node.js Utilizes RethinkDB WebSockets Medium sized API @faisalabid +faisalabidx
  4. WHY SWITCH FROM NODE.JS TO DART? Tooling & debugging support

    for Node.js is a pain Already using Dart & Polymer for other front-end applications Written too many Node.js projects With that in mind, I began my investigation into Node.js and Dart @faisalabid +faisalabidx
  5. NODE.JS & DART - THE SIMILARITIES Both are great platforms

    TechEmpower.com/benchmarks/ - Both rate pretty good. Dart is slightly ahead Both are single threaded * and event based Both install and run with a very low memory footprint JIT compiled so they start up very fast and run great @faisalabid +faisalabidx
  6. NODE.JS & DART - THE DIFFERENCES Different programming paradigm Node.js’s

    multiple vm’s compared to Dart’s isolates No “forever” tool to restart Dart servers when they crash. Though easy to build into your application @faisalabid +faisalabidx
  7. PROS & CONS OF MOVING TO DART PRO: Better profiling

    and debugging in Dart PRO: Syntax and language features PRO: Organization of code is better and enforced PRO: Support for all major databases on pub.dartlang.org PRO/CON: Shift in thinking CON: Missing support for esoteric and very new database. But most protocols are JSON based so easy to port it @faisalabid +faisalabidx
  8. NOW WHAT? Node.js API written in Express What’s the Express

    alternative in Dart? @faisalabid +faisalabidx
  9. EXPRESS ALTERNATIVE IN DART Redstone Shelf by Google RPC by

    Google *There are others but these 3 are the gaining popularity* @faisalabid +faisalabidx
  10. REDSTONE Actively developed by community Very “express-y” Good community support

    for middlewares/plugins PostgresSQL Mapper MongoDB Mapper Session Management Static HTML @faisalabid +faisalabidx
  11. SHELF The base for Redstone Minimal no-frills component set to

    build a custom API framework Use middleware for routing Redstone’s middlewares come from Shelf. Both are the same Simple API @faisalabid +faisalabidx
  12. SHELF Very minimal if you can get away with it

    Simple API, compared to Express Made by Dart team @faisalabid +faisalabidx
  13. RPC The newest of the two Enables you to write

    RPC style Dart API’s easily Self documenting API Takes advantage of annotations @faisalabid +faisalabidx
  14. RPC Bit more verbose Very clear API Bonus feature. Generate

    client side libraries in Java, Python and others Made by the Dart team We went with RPC @faisalabid +faisalabidx
  15. WEBSOCKETS Market Wolf pushes data to clients in realtime using

    WebSockets Dart comes natively with WebSockets @faisalabid +faisalabidx
  16. BUILDING BLOCKS Now all the building blocks were ready Dart

    comes natively with WebSockets @faisalabid +faisalabidx
  17. DART ARCHITECTURE Easy to replicate Node.js, but we must think

    in Dart Simplify the architecture by using isolates @faisalabid +faisalabidx
  18. ISOLATES Every Dart application runs in an isolate Isolate is

    an independent worker that runs in its own memory heap Spawn multiple isolate in a VM. Take advantage of multiple cores Isolates communicate to the main isolate via a send and receive port @faisalabid +faisalabidx
  19. ISOLATES Every Dart application runs in an isolate API to

    spawn multiple isolates in a VM. Take advantage of multiple cores Isolates communicate to the main isolate via a send and receive port This fit perfectly with our design @faisalabid +faisalabidx
  20. THINKING IN DART Isolates are game changers when you develop

    Imagine spawning isolate to do database operations which don’t need to be returned to the user @faisalabid +faisalabidx
  21. DEBUGGING IN DART Debugging & Profiling applications is very simple

    using Observatory This alone justifies moving to Dart among all other things @faisalabid +faisalabidx
  22. DEPLOYING TO SERVER Node.js application used AWS Beanstalk to deploy

    application Beanstalk lets you deploy your application with a simple terminal command. Amazon handles all the scaling, load balancing and deployment for you Does not explicitly provide support for Dart But implicitly it does @faisalabid +faisalabidx
  23. RUNNING DART ON AWS BEANSTALK Beanstalk lets you deploy Docker

    images Docker is a very very lightweight virtual machine that you can configure in the form of a Dockerfile The Dockerfile describes what will go in your Docker runtime Beanstalk will deploy that image Luckily for us. Google has a base Dart VM Docker image ready for us @faisalabid +faisalabidx
  24. RUNNING DART ON AWS BEANSTALK Now that we have our

    Dockerfile ready we need to tell Beanstalk about it @faisalabid +faisalabidx
  25. RUNNING DART ON AWS BEANSTALK Now that we have our

    Dockerfile ready we need to tell Beanstalk about it Once you have that, all that you need to do is run the Elastic Beanstalk deployment command @faisalabid +faisalabidx eb deploy
  26. WAS IT WORTH IT? Yes. No question about it Dart’s

    syntax. Language features. Isolates. Observatory all make a strong compelling case to move to Dart Do we find anything missing now that we are moved away from Node.js? Not at all # lines of code shrunk dramatically. Easier to debug, deploy, less dependencies to worry about @faisalabid +faisalabidx
  27. MOVING FROM NODE.JS TO DART WAS THE BEST DECISION WE

    MADE @faisalabid +faisalabidx FOR US, ALL API PROJECTS MOVING FORWARD, WILL BE WRITTEN IN DART