$30 off During Our Annual Pro Sale. View Details »

Node.js Web Application Survey 2016

Node.js Web Application Survey 2016

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

Yosuke Furukawa
PRO

February 09, 2016
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. Node.js Web App
    Frameworks 2016
    @yosuke_furukawa

    View Slide

  2. Twitter: @yosuke_furukawa
    Github: yosuke-furukawa

    View Slide

  3. Web Application
    Frameworks 2016

    View Slide

  4. Express

    View Slide

  5. Is Express dying?
    thread is opened…

    View Slide

  6. View Slide

  7. View Slide

  8. Don’t be afraid.

    View Slide

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

    View Slide

  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?!

    View Slide

  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.

    View Slide

  12. So, don’t be afraid.

    View Slide

  13. Koa

    View Slide

  14. Koa v2.0.0

    View Slide

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

    View Slide

  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
    })

    View Slide

  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!!

    View Slide

  18. Should we use Koa v2.0
    instead of Koa v1.0 ???

    View Slide

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

    View Slide

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

    View Slide

  21. Stay tunes…

    View Slide

  22. hapi

    View Slide

  23. hapi FAQ:

    View Slide

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

    View Slide

  25. hapi stands for
    HTTP API server

    View Slide

  26. View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  31. Hapi can handle multi-type
    request lifecycle
    • onRequest
    • onPreResponse
    • onPreAuth
    • onPostAuth
    • onPreHandler
    • onPostHandler

    View Slide

  32. hapi plugins
    • joi - testing library
    • shot - fake http req/res
    • vision - template rendering
    • chairo - micro services plugins
    • lab - test utilities

    View Slide

  33. nodal

    View Slide

  34. View Slide

  35. nodal is supernova.

    View Slide

  36. In other words,
    nodal is pretty young.

    View Slide

  37. nodal is rich WAF.

    View Slide

  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

    View Slide

  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));
    }
    }

    View Slide

  40. nodal future

    View Slide

  41. conclusions

    View Slide

  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.

    View Slide