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

@stubbies/nestjs-paginate-lib

v1.0.0

Published

A reusable pagination library for NestJS and TypeORM

Downloads

15

Readme

NestJS TypeORM Pagination Lib

A reusable, opinionated library for paginating TypeORM SelectQueryBuilder results in NestJS applications. It encapsulates the logic for applying pagination (skip/take), calculates total pages, and formats the response into a standardized DTO with metadata.

Features:

  • TypeORM Support: Works directly with SelectQueryBuilder.
  • Standardized Response: Returns data alongside total, page, limit, and totalPages.
  • Swagger Ready: DTOs are decorated with @nestjs/swagger for automatic API documentation.
  • Validation: Built-in class-validator decorators for query parameters.

Installation

npm install nestjs-paginate-lib

Note: This library relies on typeorm, @nestjs/common, @nestjs/swagger, class-validator, and class-transformer as peer dependencies. Ensure they are installed in your project.


Quick Start

1. Import the Module

Import PaginationModule into your feature module or root AppModule.

import { Module } from '@nestjs/common';
import { PaginationModule } from 'nestjs-paginate-lib';

@Module({
  imports: [
    PaginationModule,
    // ... other modules
  ],
})
export class AppModule {}

2. Use in Service

Inject PaginationService and pass your TypeORM SelectQueryBuilder and the PaginationQueryDto to the paginate method.

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { PaginationService, PaginationQueryDto } from 'nestjs-paginate-lib';
import { User } from './user.entity';

@Injectable()
export class UsersService {
  constructor(
    @InjectRepository(User)
    private readonly userRepository: Repository<User>,
    private readonly paginationService: PaginationService,
  ) {}

  async findAll(paginationQuery: PaginationQueryDto) {
    const queryBuilder = this.userRepository.createQueryBuilder('user');

    queryBuilder
      .where('user.isActive = :isActive', { isActive: true })
      .orderBy('user.createdAt', 'DESC');

    return this.paginationService.paginate(queryBuilder, paginationQuery);
  }
}

3. Use in Controller

Use the PaginationQueryDto with the @Query decorator. Swagger will automatically pick up the query parameters (page and limit).

import { Controller, Get, Query } from '@nestjs/common';
import { PaginationQueryDto } from 'nestjs-paginate-lib';
import { UsersService } from './users.service';

@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Get()
  findAll(@Query() paginationQuery: PaginationQueryDto) {
    return this.usersService.findAll(paginationQuery);
  }
}

API Reference

Input: PaginationQueryDto

The PaginationQueryDto automatically handles validation and defaults.

| Field | Type | Default | Description | | :--- | :--- | :--- | :--- | | page | number | 1 | The current page number (minimum 1). | | limit | number | 10 | Items per page (minimum 1). |

Output: PaginationResponseDto<T>

The service returns a standardized JSON structure:

{
  "data": [
    {
      "id": 1,
      "name": "John Doe",
      "isActive": true
    }
    // ... items
  ],
  "meta": {
    "total": 100,
    "page": 1,
    "limit": 10,
    "totalPages": 10
  }
}
  • data: Array of items T.
  • meta.total: Total number of items in the database matching the query.
  • meta.page: Current page number.
  • meta.limit: Number of items per page.
  • meta.totalPages: Total number of pages based on the limit.

License

MIT