Slide 1

Slide 1 text

Node.js Web App Frameworks 2016 @yosuke_furukawa

Slide 2

Slide 2 text

Twitter: @yosuke_furukawa Github: yosuke-furukawa

Slide 3

Slide 3 text

Web Application Frameworks 2016

Slide 4

Slide 4 text

Express

Slide 5

Slide 5 text

Is Express dying? thread is opened…

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Don’t be afraid.

Slide 9

Slide 9 text

Express will be OK. That thread is FUD.

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

So, don’t be afraid.

Slide 13

Slide 13 text

Koa

Slide 14

Slide 14 text

Koa v2.0.0

Slide 15

Slide 15 text

All files are translated from ES.next to ES5

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Koa v2 will have breaking changes from Koa v1.

Slide 21

Slide 21 text

Stay tunes…

Slide 22

Slide 22 text

hapi

Slide 23

Slide 23 text

hapi FAQ:

Slide 24

Slide 24 text

What is hapi? What difference from Express???

Slide 25

Slide 25 text

hapi stands for HTTP API server

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

nodal

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

nodal is supernova.

Slide 36

Slide 36 text

In other words, nodal is pretty young.

Slide 37

Slide 37 text

nodal is rich WAF.

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

nodal future

Slide 41

Slide 41 text

conclusions

Slide 42

Slide 42 text

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.