In the previous video, we implemented the basic shell for a Hapijs plugin with just enough code that it registers as a plugin. This is the starting point for any plugin you build.

In this tutorial we will create a failing test for our Hapijs plugin’s elapsed time feature. Then I will briefly discuss the Hapijs reference sections for plugins and logging so that we can implement this feature.

Our elapsed time feature will be implemented by hooking into the request life cycle using a server extension for onRequest and onResponse. We will create a benchmark timer in the onRequest and then log the elapsed time in the onResponse.

Goals

  • Create elapsed time feature test
  • Review plugin docs for ext, log
  • Implement elapsed time feature

Video Info

  • Episode: CW V004
  • Skill level: Beginner with basic Node.js skills
  • Prerequisites:
    • Basic Node.js & npm
    • Basic Mocha test runner knowledge
    • Basic Chai assertion library knowledge
  • Published: May 8th, 2014
  • Tags: js, nodejs,hapi,plugin,free
  • Duration: 11:10
  • Node.js version: 0.10.25
  • Git version: 1.8.2.1

Notes

In the next video

  • Iterate on: id, method, url, status, and headers features
    • adding failing tests
    • implement features

Continue to the next video V005