Skip to content
Back to skills

Hapi

ASecurity

You are an expert in Hapi.js, the configuration-centric enterprise framework for Node.js. You help developers build production APIs with built-in input validation (Joi), authentication strategies, plugin architecture, caching, rate limiting, and comprehensive request lifecycle hooks — designed for teams that need structure, security, and testability without third-party middleware sprawl.

  • 67 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 10, 2026
developmenttypescriptgobashnodetestingapisecurity

Works with

  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned November 10, 2026

npx -y skills add ComeOnOliver/skillshub --skill hapi --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hapi?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hapi
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/comeonoliver-hapi/badge)](https://www.skillsdirectory.com/skills/comeonoliver-hapi)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Hapi — Enterprise Node.js Framework

You are an expert in Hapi.js, the configuration-centric enterprise framework for Node.js. You help developers build production APIs with built-in input validation (Joi), authentication strategies, plugin architecture, caching, rate limiting, and comprehensive request lifecycle hooks — designed for teams that need structure, security, and testability without third-party middleware sprawl.

## Core Capabilities

### Server and Routes

```typescript
import Hapi from "@hapi/hapi";
import Joi from "joi";

const server = Hapi.server({ port: 3000, host: "0.0.0.0",
  routes: { cors: { origin: ["*"], credentials: true }, validate: { failAction: "error" } },
});

// Route with built-in validation
server.route({
  method: "POST",
  path: "/api/users",
  options: {
    tags: ["api", "users"],
    description: "Create a new user",
    validate: {
      payload: Joi.object({
        name: Joi.string().min(2).max(100).required(),
        email: Joi.string().email().required(),
        role: Joi.string().valid("user", "admin").default("user"),
      }),
    },
    response: {
      schema: Joi.object({
        id: Joi.string().uuid(),
        name: Joi.string(),
        email: Joi.string(),
        role: Joi.string(),
        createdAt: Joi.date(),
      }),
    },
    auth: "jwt",
  },
  handler: async (request, h) => {
    const user = await db.users.create(request.payload);
    return h.response(user).code(201);
  },
});

// Auth strategy
await server.register(require("@hapi/jwt"));
server.auth.strategy("jwt", "jwt", {
  keys: process.env.JWT_SECRET,
  verify: { aud: "my-app", iss: "auth-service", sub: false },
  validate: (artifacts) => ({
    isValid: true,
    credentials: { user: artifacts.decoded.payload },
  }),
});
server.auth.default("jwt");

// Plugin
const usersPlugin: Hapi.Plugin<{}> = {
  name: "users",
  version: "1.0.0",
  register: async (server) => {
    server.route([
      { method: "GET", path: "/api/users", handler: listUsers },
      { method: "GET", path: "/api/users/{id}", handler: getUser },
      { method: "PUT", path: "/api/users/{id}", handler: updateUser },
      { method: "DELETE", path: "/api/users/{id}", handler: deleteUser },
    ]);
  },
};
await server.register(usersPlugin);

await server.start();
```

## Installation

```bash
npm install @hapi/hapi @hapi/joi @hapi/jwt @hapi/inert @hapi/vision
```

## Best Practices

1. **Joi validation** — Validate all input (params, query, payload, headers) at the route level; rejects bad input before handler
2. **Plugins for modularity** — Group related routes/logic into plugins; each plugin is self-contained and testable
3. **Auth strategies** — Register auth strategies (JWT, cookie, OAuth) via plugins; apply per-route or as default
4. **Response validation** — Validate outgoing responses in development; catches schema drift early
5. **Server methods** — Use `server.method()` for cached, shared functions; built-in caching with TTL
6. **Lifecycle hooks** — Use `onPreAuth`, `onPreHandler`, `onPostHandler` for cross-cutting concerns (logging, metrics)
7. **Error handling** — Use `@hapi/boom` for HTTP errors; consistent error format across all routes
8. **Testing** — Use `server.inject()` for integration tests; no HTTP overhead, test routes directly

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.