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

@kitstack/nestjs-batteries

v0.1.1

Published

A NestJS module with built-in auth, caching, and DB switching

Readme

🔋 NestJS Batteries

A drop-in NestJS module with built-in support for JWT authentication and database integration (MongoDB or SQL). Bring your own config, and we handle the rest.

npm version License: MIT TypeScript


🚀 Features

  • Plug-and-play JWT Auth - Zero-boilerplate authentication setup
  • Flexible Database Support - Switch between MongoDB and SQL (TypeORM) seamlessly
  • Environment-aware - Perfect for multi-environment deployments
  • TypeScript First - Full type safety and IntelliSense support
  • Minimal Dependencies - Lean by design, no unnecessary bloat
  • Test-friendly - Easy mocking and stubbing for unit tests

📦 Installation

npm install @kitstack/nestjs-batteries

Or with Yarn:

yarn add @kitstack/nestjs-batteries

📌 Peer Dependencies

Install the appropriate database drivers based on your setup:

For MongoDB:

npm install @nestjs/mongoose mongoose

For SQL databases:

npm install @nestjs/typeorm typeorm

# Choose your database driver:
npm install mysql2      # MySQL
npm install pg          # PostgreSQL  
npm install sqlite3     # SQLite
npm install mssql       # SQL Server

For JWT (always required if using auth):

npm install @nestjs/jwt

🔧 Quick Start

Import and configure the module in your AppModule:

import { Module } from '@nestjs/common';
import { NestJsBatteriesModule } from '@kitstack/nestjs-batteries';

@Module({
  imports: [
    NestJsBatteriesModule.forRoot({
      auth: {
        jwtModuleOptions: {
          secret: process.env.JWT_SECRET || 'your-secret-key',
          signOptions: { expiresIn: '1d' }
        }
      },
      db: {
        type: 'mongo',
        mongooseOptions: {
          uri: process.env.MONGODB_URI || 'mongodb://localhost:27017/myapp',
          options: {
            useNewUrlParser: true,
            useUnifiedTopology: true
          }
        }
      }
    })
  ],
})
export class AppModule {}

📚 Usage Examples

1. 🗃️ SQL Database (PostgreSQL) + JWT Authentication

NestJsBatteriesModule.forRoot({
  auth: {
    jwtModuleOptions: {
      secret: process.env.JWT_SECRET,
      signOptions: { expiresIn: '3h' }
    }
  },
  db: {
    type: 'sql',
    typeormOptions: {
      type: 'postgres',
      host: process.env.DB_HOST || 'localhost',
      port: parseInt(process.env.DB_PORT) || 5432,
      username: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD,
      database: process.env.DB_NAME,
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: process.env.NODE_ENV !== 'production',
      logging: process.env.NODE_ENV === 'development'
    }
  }
});

2. 🔐 JWT Authentication Only (No Database)

Perfect for microservices that only handle authentication:

NestJsBatteriesModule.forRoot({
  auth: {
    jwtModuleOptions: {
      secret: process.env.JWT_SECRET,
      signOptions: { expiresIn: '6h' }
    }
  }
});

3. 🛢️ Database Only (No Authentication)

Ideal for data-only services:

NestJsBatteriesModule.forRoot({
  db: {
    type: 'sql',
    typeormOptions: {
      type: 'mysql',
      host: process.env.DB_HOST,
      port: 3306,
      username: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD,
      database: process.env.DB_NAME,
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: false
    }
  }
});

4. 📊 MongoDB with Custom Options

NestJsBatteriesModule.forRoot({
  auth: {
    jwtModuleOptions: {
      secret: process.env.JWT_SECRET,
      signOptions: { 
        expiresIn: '24h',
        issuer: 'your-app-name'
      }
    }
  },
  db: {
    type: 'mongo',
    mongooseOptions: {
      uri: process.env.MONGODB_URI,
      options: {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        maxPoolSize: 10,
        serverSelectionTimeou