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

@nybkox/nest-gitlab

v1.0.1

Published

NestJS wrapper for gitbeaker GitLab API client

Readme

GitBeaker NestJS Module

A comprehensive NestJS wrapper for @gitbeaker/rest with support for multiple GitLab instances.

Features

  • Simple configuration with forRoot() and forRootAsync()
  • Multiple GitLab instances support
  • Type-safe dependency injection
  • Decorator-based instance injection
  • Global module registration

Installation

The @gitbeaker/rest package is already installed as a dependency:

pnpm add @gitbeaker/rest

Basic Usage

Import and Configure

Import GitlabModule in your AppModule:

import { Module } from "@nestjs/common";
import { GitlabModule } from "./gitbeaker";

@Module({
  imports: [
    GitlabModule.forRoot({
      host: "https://gitlab.com",
      token: "your-personal-access-token",
    }),
  ],
})
export class AppModule {}

Inject and Use

Use the @InjectGitlabInstance() decorator to inject the GitLab instance:

import { Injectable } from "@nestjs/common";
import { InjectGitlabInstance, GitlabInstance } from "./gitbeaker";

@Injectable()
export class GitlabService {
  constructor(
    @InjectGitlabInstance() private readonly gitlab: GitlabInstance,
  ) {}

  async getProjects() {
    return await this.gitlab.Projects.all();
  }

  async getUser(userId: number) {
    return await this.gitlab.Users.show(userId);
  }
}

Async Configuration

Use forRootAsync() for dynamic configuration:

import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { GitlabModule } from "./gitbeaker";

@Module({
  imports: [
    GitlabModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (config: ConfigService) => ({
        host: config.get("GITLAB_HOST"),
        token: config.get("GITLAB_TOKEN"),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

Multiple Instances

Configure multiple GitLab instances with unique names:

import { Module } from "@nestjs/common";
import { GitlabModule } from "./gitbeaker";

@Module({
  imports: [
    // Default instance
    GitlabModule.forRoot({
      host: "https://gitlab.com",
      token: "token-1",
    }),
    // Named instance
    GitlabModule.forRoot({
      name: "enterprise",
      host: "https://gitlab.enterprise.com",
      token: "token-2",
    }),
  ],
})
export class AppModule {}

Inject named instances:

import { Injectable } from "@nestjs/common";
import { InjectGitlabInstance, GitlabInstance } from "./gitbeaker";

@Injectable()
export class MultiGitlabService {
  constructor(
    @InjectGitlabInstance() private readonly defaultGitlab: GitlabInstance,
    @InjectGitlabInstance("enterprise")
    private readonly enterpriseGitlab: GitlabInstance,
  ) {}

  async getPublicProjects() {
    return await this.defaultGitlab.Projects.all();
  }

  async getEnterpriseProjects() {
    return await this.enterpriseGitlab.Projects.all();
  }
}

Configuration Options

The module accepts all options supported by @gitbeaker/rest:

interface GitlabModuleOptions {
  // Instance name for multiple instances (defaults to 'default')
  name?: string;

  // GitLab host URL
  host?: string;

  // Personal access token
  token?: string;

  // OAuth token
  oauthToken?: string;

  // Job token
  jobToken?: string;

  // Additional @gitbeaker/rest options
  [key: string]: unknown;
}

API Reference

Module Methods

  • GitlabModule.forRoot(options) - Synchronous configuration
  • GitlabModule.forRootAsync(options) - Asynchronous configuration

Decorators

  • @InjectGitlabInstance(name?) - Inject a GitLab instance

Types

  • GitlabInstance - Type for the GitLab instance
  • GitlabModuleOptions - Configuration options
  • GitlabModuleAsyncOptions - Async configuration options

Example: Complete Service

import { Injectable, Logger } from "@nestjs/common";
import { InjectGitlabInstance, GitlabInstance } from "./gitbeaker";

@Injectable()
export class ProjectService {
  private readonly logger = new Logger(ProjectService.name);

  constructor(
    @InjectGitlabInstance() private readonly gitlab: GitlabInstance,
  ) {}

  async getProject(projectId: number) {
    try {
      return await this.gitlab.Projects.show(projectId);
    } catch (error) {
      this.logger.error(`Failed to fetch project ${projectId}`, error);
      throw error;
    }
  }

  async getProjectIssues(projectId: number) {
    return await this.gitlab.Issues.all({ projectId });
  }

  async getMergeRequests(projectId: number) {
    return await this.gitlab.MergeRequests.all({ projectId });
  }

  async createBranch(projectId: number, branchName: string, ref: string) {
    return await this.gitlab.Branches.create(projectId, branchName, ref);
  }
}

Resources