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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@crdsyntax/nest-module

v1.4.2

Published

generate nest module with basic interface using nestjs, typeorm, swagger

Readme

Nest Module Generator

A small utility script that scaffolds a NestJS module with common building blocks (module, service, controller), plus folders and files commonly used in a CRUD module: DTOs, entity, repository, tests, and extra folders.

This repository contains the script at bin/generate-module.js which automates invoking the Nest CLI and then creates & rearranges files into a standard module layout.

Quick summary

  • Script: bin/generate-module.js
  • Purpose: Generate a NestJS module scaffold (module/service/controller) and add commonly used files and folders (entities, dto, repositories, services, controllers, tests).
  • Language: Node.js (plain JavaScript)

Requirements

  • Node.js (tested with Node 12+; use a modern LTS version)
  • Internet access for npx @nestjs/cli (the script runs Nest CLI via npx)
  • A NestJS project structure with a src/ folder (the script generates src/<module-name>)
  • Optional: typeorm and @nestjs/swagger if you want the generated files to compile without additional changes

Installation / make executable

Clone the repository and (optionally) make the script executable:

git clone <repo-url>
cd nest-module
chmod +x ./bin/generate-module.js

You can run it with node or directly if executable.

Usage

Run the script from the repository root (or adjust path accordingly):

# using node
node ./bin/generate-module.js MyModuleName

# or, if executable
./bin/generate-module.js MyModuleName

Examples (input name formats accepted):

  • UserProfile (PascalCase)
  • userProfile (camelCase)
  • user-profile (kebab-case)

The script will convert the provided name into kebab-case for folder names and into PascalCase for class names. For example, userProfile -> module folder src/user-profile and class UserProfile.

What the script does

  1. Calls the Nest CLI to generate the module, service and controller:

    • npx @nestjs/cli g module <kebab-name>
    • npx @nestjs/cli g service <kebab-name>
    • npx @nestjs/cli g controller <kebab-name>
  2. Creates a set of folders under src/<kebab-name>:

    • services/
    • controllers/
    • dto/
    • entities/
    • tests/
    • repositories/
  3. Creates or writes several files (if they don't already exist):

    • entities/<kebab-name>.entity.ts — basic TypeORM entity scaffold
    • dto/create-<kebab-name>.dto.ts — Swagger-decorated create DTO
    • dto/update-<kebab-name>.dto.ts — PartialType-based update DTO
    • repositories/<kebab-name>.repository.ts — basic repository using @InjectRepository and Repository<T>
  4. Moves the generated service and controller files into the services/ and controllers/ folders respectively, rewrites them with templates that delegate to the repository and include Swagger decorators for the controller.

Example generated structure

After running node ./bin/generate-module.js userProfile you should see (roughly):

src/
└── user-profile/
    ├── controllers/
    │   └── user-profile.controller.ts
    ├── dto/
    │   ├── create-user-profile.dto.ts
    │   └── update-user-profile.dto.ts
    ├── entities/
    │   └── user-profile.entity.ts
    ├── repositories/
    │   └── user-profile.repository.ts
    ├── services/
    │   └── user-profile.service.ts
    ├── tests/
    │   ├── user-profile.controller.spec.ts
    │   └── user-profile.service.spec.ts
    └── user-profile.module.ts

Short description of generated files

  • entity: a TypeORM @Entity() class with id, name and date columns.
  • DTOs: Create...Dto with @ApiProperty() and Update...Dto based on PartialType.
  • repository: an injectable class that wraps Repository<T> and provides basic CRUD helper methods.
  • service: thin service that delegates to the repository and wraps calls with try/catch and HttpExceptions in the template.
  • controller: CRUD endpoints with Swagger decorators and request validation pipes (e.g., ParseIntPipe).

Notes & caveats

  • The script depends on npx @nestjs/cli and will try to run it automatically; ensure you have network access or @nestjs/cli installed globally.
  • The generated TypeScript templates may contain small issues that should be reviewed before compiling (for example, some date-decorator names or variable references in templates may require correction). Please inspect files like the entity and service templates and adjust imports / names if TypeScript compilation fails.
  • The script only writes some files if they don't already exist (it checks with fs.existsSync before writing certain files). It will, however, use the Nest CLI which may overwrite files generated by the CLI itself before the script moves them.

Suggested improvements (low-risk)

  • Fix small typos in the generated entity/service templates (e.g., UpdateDatecolumn -> UpdateDateColumn).
  • Replace any undefined template variables (like pascalName if present) with the computed class name.
  • Add an optional --force flag to overwrite existing files explicitly.
  • Add unit tests that validate the generator's output structure and minimal TypeScript compilation.

Troubleshooting

  • If you see TypeScript errors after generation, open the generated files under src/<kebab-name> and inspect import names and decorator casing.
  • If npx fails, try installing the Nest CLI globally: npm i -g @nestjs/cli and re-run the script.

License

This project inherits the repository license (if any). Use the script freely within the constraints of that license.


If you'd like, I can also fix the small typos and template inconsistencies in bin/generate-module.js so the generated files compile cleanly. Let me know if you want me to apply those improvements.