CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nestjs--cli

Command-line interface tool for initializing, developing, and maintaining NestJS applications

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

library-integration.mddocs/

Library Integration

Add external libraries to your NestJS project with automated setup, configuration, and integration. The add command streamlines the process of incorporating third-party packages and NestJS-specific libraries into your application.

Capabilities

Add Command

Integrates external libraries with automated setup and configuration management.

# Add library to project
nest add <library> [options] [library-specific-options]

# Options:
-d, --dry-run                       # Report actions without writing results
-s, --skip-install                  # Skip package installation (default: false)
-p, --project [project]             # Project in which to generate files
[library-specific-options]         # Additional options passed to the library's schematic

Usage Examples:

# Add Swagger/OpenAPI support
nest add @nestjs/swagger

# Add GraphQL support
nest add @nestjs/graphql

# Add database integration
nest add @nestjs/typeorm
nest add @nestjs/mongoose

# Add authentication
nest add @nestjs/passport

# Preview changes without installing
nest add @nestjs/swagger --dry-run

# Add to specific project in monorepo
nest add @nestjs/swagger --project api-gateway

# Skip automatic package installation
nest add @nestjs/swagger --skip-install

Supported Libraries

Core NestJS Libraries

Official NestJS packages with automated integration:

# Web Framework Enhancements
nest add @nestjs/swagger              # OpenAPI/Swagger documentation
nest add @nestjs/graphql              # GraphQL API development
nest add @nestjs/websockets           # WebSocket support
nest add @nestjs/microservices        # Microservices architecture

# Database Integration
nest add @nestjs/typeorm              # TypeORM database integration
nest add @nestjs/mongoose             # MongoDB with Mongoose
nest add @nestjs/sequelize            # Sequelize ORM
nest add @nestjs/prisma               # Prisma database toolkit

# Authentication & Security
nest add @nestjs/passport             # Passport authentication
nest add @nestjs/jwt                  # JSON Web Token support
nest add @nestjs/throttler            # Rate limiting

# Caching & Performance
nest add @nestjs/cache-manager        # Caching solutions
nest add @nestjs/bull                 # Queue management
nest add @nestjs/schedule             # Task scheduling

# Monitoring & Logging
nest add @nestjs/terminus             # Health checks
nest add @nestjs/logger               # Enhanced logging

# Configuration
nest add @nestjs/config               # Configuration management
nest add @nestjs/serve-static         # Static file serving

Third-Party Libraries

Many popular Node.js libraries with NestJS schematics:

# State Management
nest add @ngrx/store                  # Redux-style state management

# Validation
nest add class-validator              # Decorator-based validation
nest add joi                          # Schema validation

# Testing
nest add @nestjs/testing              # Enhanced testing utilities

# Development Tools
nest add @nestjs/devtools-integration # NestJS DevTools

Library-Specific Options

Many libraries accept additional configuration options during installation:

Swagger Integration

# Basic Swagger setup
nest add @nestjs/swagger

# With custom configuration
nest add @nestjs/swagger --project api --title "My API" --version "1.0"

GraphQL Setup

# Apollo GraphQL (default)
nest add @nestjs/graphql

# With schema-first approach
nest add @nestjs/graphql --schemaFirst

# With custom configuration
nest add @nestjs/graphql --playground --introspection

TypeORM Database

# Basic TypeORM setup
nest add @nestjs/typeorm

# With specific database
nest add @nestjs/typeorm --database postgres
nest add @nestjs/typeorm --database mysql
nest add @nestjs/typeorm --database sqlite

Installation Process

Automated Steps

When adding a library, the CLI typically performs:

  1. Package Installation: Downloads and installs the library and its dependencies
  2. Code Generation: Creates configuration files and boilerplate code
  3. Module Registration: Updates app.module.ts or creates feature modules
  4. Configuration Setup: Adds necessary configuration files
  5. Import Updates: Updates import statements and module dependencies

Example: Adding Swagger

nest add @nestjs/swagger

Generated Changes:

  • Installs @nestjs/swagger and swagger-ui-express
  • Updates main.ts with Swagger configuration
  • Adds OpenAPI decorators to controllers
  • Creates Swagger documentation endpoint at /api

Example: Adding TypeORM

nest add @nestjs/typeorm

Generated Changes:

  • Installs @nestjs/typeorm, typeorm, and database driver
  • Creates ormconfig.json or database configuration
  • Updates app.module.ts with TypeORM module
  • Generates entity and repository examples
  • Sets up database connection configuration

Project Structure Impact

Configuration Files

Added libraries often create configuration files:

project-root/
├── ormconfig.json              # TypeORM configuration
├── .env                        # Environment variables
├── swagger-config.json         # Swagger configuration
└── src/
    ├── config/                 # Configuration modules
    ├── entities/              # Database entities
    └── modules/               # Feature modules

Module Structure

Libraries typically integrate into the module system:

// app.module.ts after adding libraries
@Module({
  imports: [
    ConfigModule.forRoot(),
    TypeOrmModule.forRoot({
      // Database configuration
    }),
    GraphQLModule.forRoot({
      // GraphQL configuration
    }),
    // Other modules...
  ],
})
export class AppModule {}

Monorepo Support

Project-Specific Installation

# Add to specific application
nest add @nestjs/swagger --project api-gateway
nest add @nestjs/typeorm --project user-service

# Add to shared library
nest add @nestjs/common --project shared-utils

Cross-Project Dependencies

Some libraries can be shared across monorepo projects:

# Add shared authentication library
nest add @nestjs/passport --project auth-lib

# Add project-specific database connection
nest add @nestjs/typeorm --project user-service

Advanced Integration

Custom Schematics

Some libraries provide custom schematics for advanced setup:

# Run specific library schematics
nest add @my-org/custom-lib --schematic advanced-setup
nest add @nestjs/graphql --schematic federation

Configuration Options

Pass configuration directly during installation:

# Complex configuration
nest add @nestjs/typeorm \
  --database postgres \
  --host localhost \
  --port 5432 \
  --synchronize false

Dry Run and Validation

Preview Changes

# See what would be changed
nest add @nestjs/swagger --dry-run

Dry Run Output:

  • Lists files that would be created
  • Shows files that would be modified
  • Displays packages that would be installed
  • Previews configuration changes

Manual Installation

# Skip automatic package installation
nest add @nestjs/swagger --skip-install

# Then manually install
npm install @nestjs/swagger swagger-ui-express

Common Integration Patterns

API Documentation

# Complete API documentation setup
nest add @nestjs/swagger
nest add @nestjs/config  # For environment-based configuration

Database with Auth

# Full backend setup
nest add @nestjs/typeorm
nest add @nestjs/passport
nest add @nestjs/jwt
nest add @nestjs/config

GraphQL API

# GraphQL with database
nest add @nestjs/graphql
nest add @nestjs/typeorm
nest add apollo-server-express

Error Handling

Invalid Library Names

# Unknown library
nest add unknown-library
# Error: Schematic "ng-add" not found in collection "unknown-library"

Dependency Conflicts

The CLI detects and reports dependency conflicts:

  • Version incompatibilities
  • Peer dependency requirements
  • Duplicate installations

Installation Failures

If package installation fails, the CLI:

  • Reports the specific error
  • Suggests manual installation steps
  • Provides rollback instructions
  • Preserves existing project state

docs

application-building.md

code-generation.md

development-server.md

index.md

library-integration.md

project-creation.md

project-information.md

tile.json