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

smile-nestjs-got

v0.2.0

Published

A NestJS HTTP module built on got

Readme

smile-nestjs-got

A NestJS HTTP module built on got, exposing got's request, streaming and pagination APIs through RxJS Observables.

The module/service surface intentionally mirrors the official @nestjs/axios (HttpModule / HttpService), so migrating from axios is mostly mechanical.

When to use this (and when not)

Already happy with @nestjs/axios? Keep it. Migrating touches every call site (request options, error classes, stricter JSON parsing), and that cost isn't worth paying for features you don't need.

This package is for you when:

  • You're starting a new service and want got's extras from day one: built-in retries and pagination (axios has neither), granular per-phase timeouts, and first-class streaming with upload/download progress events.
  • You already wanted got but were blocked by its pure-ESM packaging in a CommonJS NestJS app — this package removes that hurdle entirely.
  • You've outgrown axios on a specific pain: hand-rolled retry interceptors, pagination loops, streaming ergonomics, or HTTP/2.

The @nestjs/axios-compatible surface isn't the reason to switch — it's what makes switching cheap once you have a reason.

Requirements

  • Node.js >= 20.19 (AbortSignal.any is used internally; got ^15 and ^16 require Node >= 22)
  • got ^14 || ^15 || ^16 (peer dependency)

This package is published as CommonJS and loads got via dynamic import(), so it works in both CommonJS and ESM NestJS applications without any extra setup.

Installation

npm i smile-nestjs-got got

Usage

Register the module

import { Module } from '@nestjs/common';
import { HttpModule } from 'smile-nestjs-got';

@Module({
  imports: [
    HttpModule.register({
      prefixUrl: 'https://api.example.com',
      headers: { 'user-agent': 'my-app' },
      // global: true, // register as a global module
    }),
  ],
})
export class AppModule {}

Async registration

HttpModule.registerAsync({
  imports: [ConfigModule],
  inject: [ConfigService],
  useFactory: (config: ConfigService) => ({
    prefixUrl: config.getOrThrow<string>('API_URL'),
  }),
});

useClass / useExisting (implementing HttpModuleOptionsFactory with createHttpOptions()) and extraProviders are also supported.

Making requests

import { Injectable } from '@nestjs/common';
import { firstValueFrom } from 'rxjs';
import { HttpService } from 'smile-nestjs-got';

@Injectable()
export class CatsService {
  constructor(private readonly httpService: HttpService) {}

  async findAll() {
    const response = await firstValueFrom(this.httpService.get<Cat[]>('cats'));
    return response.data; // alias of response.body
  }
}

HttpService exposes request, head, get, post, put, patch, delete, each returning an Observable<HttpResponse<T>> (head has no body, so it returns Observable<HttpResponse<string>>). Passing responseType: 'text' or 'buffer' narrows the body type to string / Uint8Array automatically via overloads. Unsubscribing aborts the underlying request via AbortController. A signal you pass in the options is merged with the internal one, so either can abort the request — your signal's abort surfaces as an error on the Observable.

All methods default to responseType: 'json' except head (HEAD responses have no body to parse). Empty 2xx bodies are fine (got returns ''), but a non-empty, non-JSON 2xx body throws a ParseError — pass responseType: 'text' for such endpoints:

this.httpService.post('jobs/1/restart', { responseType: 'text' });

HttpResponse<T> is got's Response<T> plus axios-compatible aliases:

| axios alias | got native | | --------------------- | ------------------------ | | response.data | response.body | | response.status | response.statusCode | | response.statusText | response.statusMessage |

Pagination (got extra)

// Emit one array with every item across all pages:
this.httpService.pagination.all<Item>('items');

// Emit each item individually:
this.httpService.pagination.each<Item>('items');

Streaming (got extra)

// Returns the raw got Duplex stream — pipe it wherever you need:
const stream = this.httpService.stream.get('large-file');
stream.pipe(res);

Raw got instance

this.httpService.gotRef; // the underlying got instance
this.httpService.axiosRef; // alias of gotRef (for @nestjs/axios compatibility)

Migrating from @nestjs/axios

See MIGRATION.md for the full step-by-step guide.

The dependency-injection surface is identical, so wiring stays the same:

// Before
import { HttpModule, HttpService } from '@nestjs/axios';
// After
import { HttpModule, HttpService } from 'smile-nestjs-got';

HttpModule.register / registerAsync, global, extraProviders, axiosRef, request() and the HttpResponse.data/status/statusText aliases all carry over. What changes is got's request options and semantics (not the NestJS glue):

| @nestjs/axios | smile-nestjs-got | Notes | | ----------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------- | | baseURL | prefixUrl | got forbids a leading / on the path | | data (body) | json / body / form | choose by content type | | params | searchParams | | | timeout: 1000 | timeout: { request: 1000 } | got uses granular timeouts | | responseType: 'arraybuffer' | responseType: 'buffer' | blob / document unsupported | | axios.interceptors.* | hooks.beforeRequest / hooks.afterResponse | got hooks | | postForm(url, formData) | post(url, { body: formData }) | multipart — got's form: {...} is urlencoded only | | AxiosError | HTTPError / RequestError | error.response always set on HTTPError; may be undefined on RequestError (network errors) |

Example:

// Before (@nestjs/axios)
const { data } = await firstValueFrom(
  this.http.post<Cat>(
    '/cats',
    { name: 'Kitty' },
    {
      params: { q: 1 },
      headers: { authorization: `Bearer ${token}` },
    },
  ),
);

// After (smile-nestjs-got)
const { data } = await firstValueFrom(
  this.http.post<Cat>('cats', {
    json: { name: 'Kitty' },
    searchParams: { q: 1 },
    headers: { authorization: `Bearer ${token}` }, // unchanged
  }),
);