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

suvidha

v0.5.3

Published

Suvidha is a lightweight, type-safe Express.js library that adds powerful validation, middleware context management, and response handling.

Readme

Suvidha (सुविधा - Hindi for 'facility') is a lightweight, type-safe Express.js library that adds powerful validation, middleware context management, and streamlined response handling.

A utility class for building Express.js route handlers with built-in
data validation and middleware support. It allows you to define Zod
schemas for request parameters, body, and query, and chain middleware functions that can enrich the request context.

  • No Rewrites - Adopt incrementally in existing Express apps.
  • TypeScript Native - Inferred types end "guess what's in req" games.

For full documentation, see the Suvidha Documentation.

Installation

npm install suvidha

Quickstart

This example demonstrates a protected user creation endpoint with validation, authentication, and authorization.

app.ts

import express from "express";
import { Suvidha, DefaultHandlers, Formatter } from "suvidha";
import { UserSchema } from "./dto";
import { authenticate, roleCheck } from "./middlewares";
import { createUserHandler } from "./controller";

const app = express();
app.use(express.json());

const suvidha = () => Suvidha.create(new DefaultHandlers());

app.post(
    "/users",
    suvidha()
        .use(authenticate)
        .use(roleCheck)
        .body(UserSchema)
        .handler(async (req) => {
            const newUser = req.body; // Type: z.infer<typeof UserSchema>
            const { role } = req.context.user; // Type: string
            return createUserHandler(newUser, role);
        }),
);

app.listen(3000);

controller.ts

import { Http } from "suvidha";
import { UserDTO } from "./dto";

declare function createUser(
    user: UserDTO,
    role: string,
): Promise<{ id: string }>;

export async function createUserHandler(user: UserDTO, role: string) {
    try {
        const result = await createUser(user, role);
        return Http.Created.body(result);
    } catch (err: any) {
        if (err.code === "DUPLICATE_EMAIL") {
            throw Http.Conflict.body({ message: "Email already exists" });
        }
        throw err; // Propagate to Suvidha's onErr handler
    }
}

middlewares.ts

import { Http, CtxRequest } from "suvidha";

interface User {
    role: string;
    // ... other user properties
}

const verify = async (token: string): Promise<User> => {
    // ... your authentication logic
    return { role: "admin" }; // Example
};

export const authenticate = async (req: CtxRequest) => {
    const token = req.headers["authorization"];
    if (!token) {
        throw new Http.Unauthorized();
    }
    const user = await verify(token).catch((_) => {
        throw new Http.Unauthorized();
    });
    return { user };
};

export const roleCheck = (req: CtxRequest<{ user: User }>) => {
    if (req.context.user.role !== "admin") {
        throw Http.Forbidden.body({ message: "Admin access required" });
    }
    return {};
};

dto.ts

import { z } from "zod";

export const UserSchema = z.object({
    username: z.string().min(3),
    email: z.string().email(),
    age: z.number().min(13),
});

export type UserDTO = z.infer<typeof UserSchema>;

Sample Response (201 Created)

{
    "status": "success",
    "data": {
        "id": "67adc39ea1ff4e9d60273236"
    }
}

License

MIT