Sunday 22 October 2017

Hapi.js experts, what's your take on this?

So, I'm learning hapi.js and I have two books. When it comes to routing, or rather, code structuring they take two different approaches for the same thing.In the first book, they create routing in form of plugins. This is taken from the book:exports.register = function (server, options, next) { server.route({ method: 'GET', path: '/hello', handler: function (request, reply) { return reply('Hello World\n'); } }); next(); }; exports.register.attributes = { name: 'hello' }; However, in the second book, routing is just a regular node.js module:'use strict'; module.exports = [{ method: 'GET', path: '/api/recipes', handler: function (request, reply) { ... } }, { method: 'GET', path: '/api/recipes/{id}', handler: function (request, reply) { ... } }]; So, I'm a bit confused. What's the correct way here?

Submitted October 22, 2017 at 09:55AM by JavascriptFanboy

No comments:

Post a Comment