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

@takepack/core

v1.0.1

Published

A comprehensive NestJS library providing dynamic configuration management with Zod validation, TypeORM database support, migration management, seeding capabilities, and type-safe event handling

Downloads

14

Readme

@takepack/core

A comprehensive NestJS utility library providing configuration management, database operations, and event handling - all in one package.

npm version License: MIT TypeScript NestJS

📦 What's Inside

This package combines three powerful modules for NestJS applications:

  • 🔧 Config Module - Dynamic configuration management with Zod validation
  • 🗄️ Database Module - TypeORM integration with migrations and seeding
  • 📡 Event Module - Type-safe event handling system

🚀 Quick Start

Installation

npm install @takepack/core

Peer Dependencies

npm install @nestjs/common @nestjs/core @nestjs/config reflect-metadata rxjs zod

# Optional (for database features)
npm install @nestjs/typeorm typeorm

# Optional (for event features)
npm install @nestjs/event-emitter

📚 Modules Overview

1. Config Module

Dynamic configuration management with automatic loading, Zod validation, and CLI code generation.

Key Features:

  • ✅ Automatic config file loading (*.config.ts)
  • ✅ Zod schema validation for environment variables
  • ✅ CLI for generating config templates
  • ✅ Type-safe configuration access
  • ✅ Support for multiple environments

Quick Example:

import { Module } from '@nestjs/common';
import { ConfigModule } from '@takepack/core';

@Module({
  imports: [
    ConfigModule.register({
      configDir: 'src/configs',
      envFilePath: '.env',
      validate: true,
    }),
  ],
})
export class AppModule {}

CLI Usage:

# Generate all default configs
npx take-config generate --output src/configs --all

# Generate specific configs
npx take-config generate -o src/configs -c app database

# Generate custom config
npx take-config generate -o src/configs -i payment

📖 Full Config Documentation


2. Database Module

Comprehensive TypeORM integration with migration management, seeding system, and CLI commands.

Key Features:

  • ✅ Migration generation and management
  • ✅ Factory pattern for test data
  • ✅ Array-based seeder system with ordering
  • ✅ CLI commands for database operations
  • ✅ Transaction support
  • ✅ Auto-run capabilities

Quick Example:

import { Module } from '@nestjs/common';
import { DatabaseExtensionModule, DatabaseType } from '@takepack/core';

@Module({
  imports: [
    DatabaseExtensionModule.registerAsync({
      useFactory: (config: ConfigService) => ({
        connection: {
          type: DatabaseType.POSTGRES,
          host: config.get('DB_HOST'),
          port: config.get('DB_PORT'),
          username: config.get('DB_USERNAME'),
          password: config.get('DB_PASSWORD'),
          database: config.get('DB_DATABASE'),
        },
        migration: {
          enabled: true,
          migrationsPath: 'src/migrations',
          autoRun: false,
        },
        seeder: {
          enabled: true,
          seeds: [InitialSeeder, UserSeeder],
          autoRun: false,
        },
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

CLI Usage:

# Migration commands
npm run cli migration generate CreateUsersTable
npm run cli migration run
npm run cli migration revert

# Seeding commands
npm run cli seed                          # Run all seeders
npm run cli seed -- UserSeeder            # Run specific seeder
npm run cli seed -- --transaction each    # Transaction per seeder

📖 Full Database Documentation


3. Event Module

Type-safe event handling with a clean abstraction over @nestjs/event-emitter.

Key Features:

  • ✅ Type-safe event classes instead of strings
  • ✅ Decorator-based API
  • ✅ Event Bus pattern
  • ✅ Auto-completion and refactoring support
  • ✅ Zero additional dependencies

Quick Example:

// 1. Define Event
import { Event } from '@takepack/core';

@Event('user.created')
export class UserCreatedEvent {
  constructor(
    public readonly userId: string,
    public readonly email: string,
  ) {}
}

// 2. Publish Event
import { EventBus } from '@takepack/core';

@Injectable()
export class UserService {
  constructor(private eventBus: EventBus) {}

  async createUser(data: CreateUserDto) {
    const user = await this.userRepository.save(data);
    this.eventBus.publish(new UserCreatedEvent(user.id, user.email));
    return user;
  }
}

// 3. Handle Event
import { OnEventClass } from '@takepack/core';

@Injectable()
export class UserCreatedListener {
  @OnEventClass(UserCreatedEvent)
  async handleUserCreated(event: UserCreatedEvent) {
    console.log(`User ${event.email} created`);
  }
}

// 4. Register Module
@Module({
  imports: [EventsModule],
})
export class AppModule {}

📖 Full Event Documentation


🎯 Complete Example

Here's how to use all three modules together in a NestJS application:

import { Module } from '@nestjs/common';
import { 
  ConfigModule, 
  DatabaseExtensionModule, 
  EventsModule,
  DatabaseType 
} from '@takepack/core';

@Module({
  imports: [
    // Config Module
    ConfigModule.register({
      configDir: 'src/configs',
      envFilePath: '.env',
      validate: true,
    }),

    // Database Module
    DatabaseExtensionModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        connection: {
          type: DatabaseType.POSTGRES,
          host: config.get('database').host,
          port: config.get('database').port,
          username: config.get('database').username,
          password: config.get('database').password,
          database: config.get('database').database,
        },
        entities: ['dist/**/*.entity{.ts,.js}'],
        migration: {
          enabled: true,
          migrationsPath: 'src/migrations',
          autoRun: process.env.NODE_ENV === 'development',
        },
        seeder: {
          enabled: true,
          seeds: [InitialSeeder],
          autoRun: false,
        },
      }),
      global: true,
    }),

    // Event Module
    EventsModule,
  ],
})
export class AppModule {}

📦 Exports

Config Module

export { ConfigModule, ConfigService, ConfigHelpers } from '@takepack/core';

Database Module

export { 
  DatabaseExtensionModule,
  DatabaseCommandModule,
  MigrationService,
  SeederService,
  BaseFactory,
  Seeder,
  DatabaseType,
  DatabaseModuleConfig,
} from '@takepack/core';

Event Module

export { 
  EventsModule,
  EventBus,
  Event,
  OnEventClass,
} from '@takepack/core';

🛠️ Development

Build

npm run build

Test

npm test
npm run test:watch
npm run test:cov

Lint & Format

npm run lint
npm run format

📋 Requirements

  • Node.js >= 16.0.0
  • NestJS >= 10.0.0
  • TypeScript >= 5.0.0

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT © hieutran03

🔗 Links

📖 Documentation


Made with ❤️ by hieutran03