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

Node.js Web Application Survey 2016

Node.js Web Application Survey 2016

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

Yosuke Furukawa

February 09, 2016
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. 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?!
  2. 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.
  3. Koa

  4. 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 })
  5. 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!!
  6. 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
  7. 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
  8. 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
  9. 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
  10. Hapi can handle multi-type request lifecycle • onRequest • onPreResponse

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

    fake http req/res • vision - template rendering • chairo - micro services plugins • lab - test utilities
  12. 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
  13. 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)); } }
  14. 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.