npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

hapi-joier

v1.1.0

Published

Better 400 error messages for Hapi responses

Readme

Hapi Joier

Coverage Status Travis

Better Joi error messages for your 400 responses.

Usage

Just register hapi-joier and be hapi.

server.register({
  register: require('hapi-joier'),
  options: {
    enable: true
  }
})

Now your 400 replies should have better information about the invalid data.

{
  "statusCode":400,
  "error":"Bad Request",
  "message":"child \"name\" fails because [\"name\" length must be at least 10 characters long]",
  "validation":[
    {
      "message":"\"name\" length must be at least 10 characters long",
      "path":"name",
      "type":"string.min",
      "context":{
        "limit":10,
        "key":"name"
      }
    }
  ]
}

As you can see, we can now detect which test failed, this is much better to display the correct error message in the frontend.

Installation

Install this module with the command npm install --save hapi-joier, after that you are ready to register this module as a Hapi plugin.

Testing

Type the following lines inside your command line.

git clone [email protected]:alanhoff/node-hapi-joier.git
cd node-hapi-joier
npm install
npm test

Configuration

Every configuration can be made when you server.register or individually on each route.

  • enable Boolean Enable hapi-joier, if used in the server.register it will enable the plugin for every route. Default: false
  • map Function The function used to construct each validation object inside de response. It receives a Joi detail as the first parameter.

Examples

Enable hapi-joi for only one route:

// Do not pass "enable" as a option, so it won't be globally enabled
server.register(require('hapi-joi'), function()...);

server.route({
  method: 'GET',
  path: '/upload',
  method: function(request, reply){
    reply('Hello world!');
  },
  config: {
    plugins: {
      joier: {
        enable: true
      }
    }
  }
});

Change the response object with a custom map

// Do not pass "enable" as a option, so it won't be globally enabled
server.register(require('hapi-joi'), function()...);

server.route({
  method: 'GET',
  path: '/upload',
  method: function(request, reply){
    reply('Hello world!');
  },
  config: {
    plugins: {
      joier: {
        enable: true,
        map: function(detail){
          return 'Something is wrong with ' + detail.path;
        }
      }
    }
  }
});

Enable Joier for all routes and intercept every Bomm + Joi response:

server.register({
  register: require('hapi-joi'),
  options: {
    enable: true
  }
}, function()...);

License MIT

Copyright (c) 2015, Alan Hoffmeister [email protected]

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.