Plugins in hapi js
In this post I will be going over some hapi js plugin examples. A plugin in hapi like most other frameworks is just an object that is formated a certain way. There just needs to be a register property and a name at a minimum, but there are a few more properties that are also of concern.
1 - Basic Hapi plugin example
In this section I will be going over some very basic hello world style plugin examples, it is also worth noting that in this section I am using hapi 17.9.0, in older and newer versions of hapi these code examples might break.
So a very basic hapi plugin example can just be an object. This way of using plugins can be used as a good starting point when it comes to the process of breaking things down into smaller more manageable, and reusable blocks of code.
The object must have a register property and a name property. The name can just be a string, and the register must be a async function that will do whatever needs to happen for the plugin, such as setting up a path which will be what is going on in this plugin.
1.1 - Same basic example as external js
So in this sub section I will be going over what is the same example before, only now things are broken down into two completely different files.
In a module.js file I just have the following.
An then I use it in the main script just like before only now I use require to load it in.