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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hapi-scalar

v1.0.0

Published

Hapi plugin that serves API documentation using Scalar, with built-in support for hapi-swagger.

Readme

hapi-scalar

CI NPM version Checked with Biome MIT License

A Hapi plugin that serves Scalar API documentation UI for your Hapi server. It provides a modern, interactive OpenAPI/Swagger documentation interface that can be used standalone or alongside hapi-swagger.

Features

  • Serves the beautiful Scalar UI at a configurable route (default: /scalar)
  • Auto-detects and integrates with hapi-swagger configurations
  • Supports both static and dynamic configuration
  • TypeScript support

Installation

npm install hapi-scalar

Quick Start

Standalone Usage

import Hapi from '@hapi/hapi'
import hapiScalar from 'hapi-scalar'

const server = Hapi.server({
  port: 3000,
  host: 'localhost',
})

await server.register({
  plugin: hapiScalar,
  options: {
    scalarConfig: {
      url: '/path/to/your/openapi.json', // Your OpenAPI spec URL
    },
  },
})

await server.start()
console.log('Documentation available at: http://localhost:3000/scalar')

Visit http://localhost:3000/scalar to view the Scalar UI.

With hapi-swagger

When used with hapi-swagger, the plugin automatically detects your OpenAPI/Swagger configuration:

import Hapi from '@hapi/hapi'
import Inert from '@hapi/inert'
import Vision from '@hapi/vision'
import HapiSwagger from 'hapi-swagger'
import hapiScalar from 'hapi-scalar'

const server = Hapi.server({
  port: 3000,
  host: 'localhost',
})

// Configure hapi-swagger
const swaggerOptions = {
  info: {
    title: 'My API Documentation',
    version: '1.0.0',
    description: 'This is my awesome API',
  },
  OAS: 'v3.0', // Use OpenAPI 3.0
}

// Register dependencies and hapi-swagger
await server.register([
  Inert,
  Vision,
  { plugin: HapiSwagger, options: swaggerOptions },
])

// Register hapi-scalar - it will automatically use the OpenAPI spec from hapi-swagger
await server.register({
  plugin: hapiScalar,
  options: {
    // Optional: customize the documentation route
    routePrefix: '/docs',
    // Optional: customize Scalar UI
    scalarConfig: {
      hideClientButton: false,
      theme: 'purple',
    },
  },
})

await server.start()
console.log('API Documentation available at: http://localhost:3000/docs')

Note: When hapi-swagger is registered, hapi-scalar automatically uses /openapi.json if OAS is 'v3.0', otherwise /swagger.json. You don’t need to set scalarConfig.url manually.

Configuration Options

Plugin Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | routePrefix | string | '/scalar' | The path where the Scalar documentation UI will be served. | | scalarConfig | object \| function(request) => object \| Promise<object> | {} | Configuration passed to the Scalar UI. Can be a static object or a dynamic function that receives the Hapi request. |

Example:

await server.register({
  plugin: hapiScalar,
  options: {
    routePrefix: '/docs',           // → http://localhost:3000/docs
    scalarConfig: { /* ... */ },    // Scalar UI configuration
  },
})

The scalarConfig object supports all Scalar configuration options.

Dynamic Configuration

Use a function to provide dynamic configuration based on the request:

options: {
  scalarConfig: (request) => {
    return { 
      theme: request.query.theme ?? 'default',
      hideClientButton: true
    }
  }
}

// You can also return a Promise or use an async function:
options: {
  scalarConfig: async (request) => {
    // e.g., fetch from a database or remote config service
    const url = request.query.specUrl || '/openapi.json'
    return { url }
  },
}

TypeScript

Type definitions are included. Example:

import Hapi from '@hapi/hapi'
import hapiScalar from 'hapi-scalar'

const options: hapiScalar.RegisterOptions = {
  routePrefix: '/scalar',
  scalarConfig: {
    url: '/openapi.json',
    hideClientButton: true,
  },
}

await server.register({
  plugin: hapiScalar,
  options,
})

Contributing

Contributions are welcome. Please open an issue or pull request.

License

MIT


Related Projects