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

koa introduction (Node.js Web Framework)

andre
October 23, 2014

koa introduction (Node.js Web Framework)

koa is a Node.js Web Framework. I've demonstrated some examples and also introduced some basic concepts in this internal sharing.

andre

October 23, 2014
Tweet

More Decks by andre

Other Decks in Programming

Transcript

  1. agenda • What is koa • Before Diving in koa

    • Hello koa • Running koa in Production?
  2. agenda • What is koa • Before Diving in koa

    • Hello koa • Running koa in Production?
  3. Node.js Web Frameworks • Express • Minimal, Muture, Ecosystem •

    hapi • Rich Framework • LoopBack • For creating APIs
  4. Node.js Web Frameworks • Express • Minimal, Muture, Ecosystem •

    hapi • Rich Framework • LoopBack • For creating APIs
  5. Node.js Web Frameworks • Express • Minimal, Muture, Ecosystem •

    hapi • Rich Framework • LoopBack • For creating APIs
  6. Node.js Web Frameworks • Express • Minimal, Muture, Ecosystem •

    hapi • Rich Framework • LoopBack • For creating APIs
  7. What is koa • Node.js Web Framework • Developed by

    Part of Express Team • Generators via co
  8. What is koa • Node.js Web Framework • Developed by

    Part of Express Team • Generators via co
  9. What is koa • Node.js Web Framework • Developed by

    Part of Express Team • Generators via co
  10. What is koa • Node.js Web Framework • Developed by

    Part of Express Team • Generators via co • Minimal Core
  11. agenda • What is koa • Before Diving in koa

    • Hello koa • Running koa in Production?
  12. Generators • ECMAScript Harmony (6th Edition) • Chrome: about:flags ➛

    Enable Experimental JavaScript • Firefox 33.0 • Iterator
  13. Generators • ECMAScript Harmony (6th Edition) • Chrome: about:flags ➛

    Enable Experimental JavaScript • Firefox 33.0 • Iterator • next()
  14. Generators • ECMAScript Harmony (6th Edition) • Chrome: about:flags ➛

    Enable Experimental JavaScript • Firefox 33.0 • Iterator • next() • throw StopIteration
  15. Generators • ECMAScript Harmony (6th Edition) • Chrome: about:flags ➛

    Enable Experimental JavaScript • Firefox 33.0 • Iterator • next() • throw StopIteration https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
  16. Generators • ECMAScript Harmony (6th Edition) • Chrome: about:flags ➛

    Enable Experimental JavaScript • Firefox 33.0 • Iterator • next() • throw StopIteration • yield
  17. Generators • ECMAScript Harmony (6th Edition) • Chrome: about:flags ➛

    Enable Experimental JavaScript • Firefox 33.0 • Iterator • next() • throw StopIteration • yield https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
  18. thunkify co will execute next() when callback http://jsbin.com/xubajo/edit // 3

    // 4 // 3 https://github.com/tj/node-thunkify/blob/master/index.js
  19. Yieldables • promises • thunks (functions) • array (parallel execution)

    • objects (parallel execution) • generators (delegation) • generator functions (delegation)
  20. agenda • What is koa • Before Diving in koa

    • Hello koa • Running koa in Production?
  21. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer
  22. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading
  23. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading • Settings
  24. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading • Settings
  25. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading • Settings • app.listen(...)
  26. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading • Settings • app.listen(...) • app.callback()
  27. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading • Settings • app.listen(...) • app.callback() • app.use(function)
  28. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading • Settings • app.listen(...) • app.callback() • app.use(function) • app.keys=
  29. Hello koa • Requires node 0.11.x for the --harmony flag

    • Application • To provide high level "sugar" at the otherwise low-level middleware layer • Cascading • Settings • app.listen(...) • app.callback() • app.use(function) • app.keys= • Error Handling
  30. Hello koa (Cont’d) • Context ctx.req ➛ node’s request ctx.res

    ➛ node’s response ctx.request ➛ koa’s request ctx.response ➛ koa’s response
  31. Hello koa (Demo) • 00_hello_world.js • 01_cascading.js • 02_thunkify.js •

    03_routing.js • 04_error_handling.js • 05_request.js • 06_mongo.js • 07_redis.js • 08_ejs.js
  32. agenda • What is koa • Before Diving in koa

    • Hello koa • Running koa in Production?
  33. Running koa in Production? • TJ for GO lang, Express

    to Strongloop • Using co’s ecosystem
  34. Running koa in Production? • TJ for GO lang, Express

    to Strongloop • Using co’s ecosystem • Node.js v0.11.x is unstable
  35. Running koa in Production? • TJ for GO lang, Express

    to Strongloop • Using co’s ecosystem • Node.js v0.11.x is unstable • Generators
  36. Running koa in Production? • TJ for GO lang, Express

    to Strongloop • Using co’s ecosystem • Node.js v0.11.x is unstable • Generators • Better Performance?
  37. Running koa in Production? • TJ for GO lang, Express

    to Strongloop • Using co’s ecosystem • Node.js v0.11.x is unstable • Generators • Better Performance? from https://medium.com/javascript-and-the-server
  38. Running koa in Production? • TJ for GO lang, Express

    to Strongloop • Using co’s ecosystem • Node.js v0.11.x is unstable • Generators • Better Performance?