How do Express and hapi compare to each other?

后端 未结 6 2062
耶瑟儿~
耶瑟儿~ 2020-12-12 08:51

From web application design and development point of view, how do Express and Hapi compare to each other? For basic examples they seem similar, however I\'m interested to le

6条回答
  •  暖寄归人
    2020-12-12 09:32

    I've started using Hapi recently and I'm quite happy with it. My reasons are

    1. Easier to test. For example:

      • server.inject allows you to run the app and get a response without it running and listening.
      • server.info gives the current uri, port etc.
      • server.settings accesses the configuration e.g. server.settings.cache gets current cache provider
      • when in doubt look at the /test folders for any part of the app or supported plugins to see suggestions on how to mock/test/stub etc.
      • my sense is that the architectural model of hapi allows you to trust but verify e.g. Are my plugins registered? How can I declare a module dependency?
    2. It works out of the box e.g. file uploads, return streams from endpoints etc.

    3. Essential plugins are maintained along with the core library. e.g template parsing, caching etc. The added benefit is the same coding standards are applied across the essential things.

    4. Sane errors and error handling. Hapi validates config options and keeps an internal route table to prevent duplicate routes. This is quite useful while learning because errors are thrown early instead of unexpected behaviours which require debugging.

提交回复
热议问题