hapi-method-loader

Automatically loads hapi methods

Usage no npm install needed!

<script type="module">
  import hapiMethodLoader from 'https://cdn.skypack.dev/hapi-method-loader';
</script>

README

hapi-method-loader Build Status

Automatically loads methods from a directory.

Installation

npm install hapi-method-loader

Usage

server.register({
  register: require('hapi-method-loader'),
  // options: {}
});

Options

  • cwd - Defaults to process.cwd()
  • methods - Relative to cwd. Defaults to methods

Methods

Each method should be a file in the methods directory. Sub directories may be used for nested methods. File name will dictate method name.

Each method should export a method function and optionally an options object.

Example:

module.exports = {
  method: function(next) {
    return next(null, new Date());
  },
  options: {
    cache: {
      expiresIn: 60 * 60 * 1000
    },
    generateKey: function() {
      return 'getTimeExample';
    }
  }
};