Node.js Web Application Survey 2016

Node.js Web Application Survey 2016

Node学園 19時限目資料です。 

D76231a2114896dfcc7b79ac69558b79?s=128

Yosuke Furukawa

February 09, 2016
Tweet

Transcript

  1. Node.js Web App Frameworks 2016 @yosuke_furukawa

  2. Twitter: @yosuke_furukawa Github: yosuke-furukawa

  3. Web Application Frameworks 2016

  4. Express

  5. Is Express dying? thread is opened…

  6. None
  7. None
  8. Don’t be afraid.

  9. Express will be OK. That thread is FUD.

  10. Discussion point • IBM is not OSS company. • Doug

    Willson will stay express project permanently? • Express release schedule is not clear… • when express v5 is released?!
  11. Discussion point • IBM is not OSS company.
 → Node

    Foundation will incubate Express and those libraries. • Doug Willson will stay express project permanently?
 → Express WG is established. • Express release schedule is not clear…
 → DougWillson will move forward to the schedule.
  12. So, don’t be afraid.

  13. Koa

  14. Koa v2.0.0

  15. All files are translated from ES.next to ES5

  16. Koa v2.0.0 // Koa application is now a class and

    requires the new operator. const app = new Koa() // uses async arrow functions app.use(async (ctx, next) => { try { await next() // next is now a function } catch (err) { ctx.body = { message: err.message } ctx.status = err.status || 500 } }) app.use(async ctx => { const user = await User.getById(ctx.session.userid) // await instead of yield ctx.body = user // ctx instead of this })
  17. Koa v2.0.0 // Koa application is now a class and

    requires the new operator. const app = new Koa() // uses async arrow functions app.use(async (ctx, next) => { try { await next() // next is now a function } catch (err) { ctx.body = { message: err.message } ctx.status = err.status || 500 } }) app.use(async ctx => { const user = await User.getById(ctx.session.userid) // await instead of yield ctx.body = user // ctx instead of this }) Yes!!! you can use async/await on Koa v2!!
  18. Should we use Koa v2.0 instead of Koa v1.0 ???

  19. Not now. please wait. currently Koa v2.0 is alpha.

  20. Koa v2 will have breaking changes from Koa v1.

  21. Stay tunes…

  22. hapi

  23. hapi FAQ:

  24. What is hapi? What difference from Express???

  25. hapi stands for HTTP API server

  26. None
  27. Express const express = require('express'); const app = express(); app.get('/hello',

    (req, res) => { res.send('hello world'); }); app.listen(‘3000’, (err) => { if (err) { throw err; } console.log('Server running at: 3000'); }); SPVUFSBTBDPEF
  28. hapi const Hapi = require('hapi'); const server = new Hapi.Server();

    server.connection({ host: 'localhost', port: 8000 }); server.route({ method: 'GET', path:'/hello', handler: (request, reply) => { return reply('hello world'); } }); server.start((err) => { if (err) { throw err; } console.log('Server running at:', server.info.uri); }); SPVUFSBTB DPOpHVSBUJPO
  29. Express const express = require('express'); const app = express(); app.get('/hello',

    (req, res) => { app.render(‘view’, {name: ‘Tobi’}); }); app.listen(‘3000’, (err) => { if (err) { throw err; } console.log('Server running at: 3000'); }); SFTSFOEFSJTVTFGVMGPS SFOEFSJOHIUNM
  30. hapi does not have res.render const Hapi = require('hapi'); const

    server = new Hapi.Server(); server.connection({ host: 'localhost', port: 8000 }); server.route({ method: 'GET', path:'/hello', handler: (request, reply) => { return reply('hello world'); } }); server.start((err) => { if (err) { throw err; } console.log('Server running at:', server.info.uri); }); SFQMZDBOIBOEMF#V⒎FS 1SPNJTF  4USFBN
  31. Hapi can handle multi-type request lifecycle • onRequest • onPreResponse

    • onPreAuth • onPostAuth • onPreHandler • onPostHandler
  32. hapi plugins • joi - testing library • shot -

    fake http req/res • vision - template rendering • chairo - micro services plugins • lab - test utilities
  33. nodal

  34. None
  35. nodal is supernova.

  36. In other words, nodal is pretty young.

  37. nodal is rich WAF.

  38. nodal • Full staaaaaaaaaaaaaack • PostgreSQL supports (only!!) • Nodal

    can select server types • Branding Server (SEO-indexable) • API Server (just JSON) • Application Server (SinglePageApps, asset compilation) • nodal-angular
  39. nodal class BlogPostsController extends Nodal.Controller { index() { BlogPost.query() .join('user')

    .join('comments') .where(this.params.query) .end((err, blogPosts) => { this.respond(err || blogPosts); }); } show() { BlogPost.find(this.params.route.id, (err, blogPost) => this.respond(err || blogPost)); } }
  40. nodal future

  41. conclusions

  42. Node.js Web Application Frameworks 2016 • If you are express

    user, you don’t be afraid to continue to use express! • If you are koa v1.0 user or async/await lover, you would be better to be ready to upgrade koa v2.0. • If you would like to create microsevices nodes and getting tired of using express, you need to know more about hapi. • If you would like to know more new application frameworks, you should use nodal.