Skip to content

Instantly share code, notes, and snippets.

@kimmobrunfeldt
Last active July 6, 2016 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimmobrunfeldt/4deab76701dde1d611abf6de6e36811f to your computer and use it in GitHub Desktop.
Save kimmobrunfeldt/4deab76701dde1d611abf6de6e36811f to your computer and use it in GitHub Desktop.
Hapi for Express developers

Hapi for Express developers

(My opinionated view as an Express developer)

Check this post: http://matt-harrison.com/moving-from-express-to-hapi-js/ and how to use Hapi plugins: https://gist.github.com/hueniverse/f01faf422eb038d87d57 written by Hapi creator Eran Hammer.

Good (in Hapi)

  • Creator Eran Hammer seems to be a smart guy and active in Hapi development

  • Stronger and bigger core ecosystem

    Meaning that the core has already solved error handling, logging etc. and they play nicely together.

    Very active development, good release notes and conventions.

    Plugins: http://hapijs.com/plugins

  • Wise defaults

    You don't need to manually setup JSON parser etc as in Express.

    IMO Hapi seems to do just enough but not too much for API backend dev.

  • Configuration over code provides nice features

    You can e.g. generate swagger API documentation from the route configuration. (https://github.com/glennjones/hapi-swagger)

    On the other hand you could form your Express code in the exact same way to accomplish the same benefit.

  • Core modules are good quality

    All option objects are validated with Joi and do not accept incorrect conf.

Not that good

  • Documentation in the core plugins are not always good

  • Configuration over code

    I don't have an example yet where this would be a bad thing but do you remember grunt, the frontend build tool? I had some cases where its configuration model wasn't rich enough.

  • Not as big community

    .. but big enough.

  • Not as simple as Express

Other points

  • Separate code to logical pieces in the hapi app architecture

    See e.g. this Express architecture: https://github.com/kimmobrunfeldt/express-example similar can and would be recommended to use with Hapi

  • Made for Walmart, Evan was hired there and this framework was created

  • Both are good, they just have a bit different approaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment