Skip to content

Instantly share code, notes, and snippets.

@Max-im
Last active September 5, 2024 15:04
Show Gist options
  • Save Max-im/8aeb97dfd86926e2724b2540f63d856e to your computer and use it in GitHub Desktop.
Save Max-im/8aeb97dfd86926e2724b2540f63d856e to your computer and use it in GitHub Desktop.
Nest.js setup

NestJS Setup Gist

Install NestJS CLI globally

npm install -g @nestjs/cli

Create a new NestJS project

nest new <project_name>

Move into the project directory

cd <project_name>

Start the application

npm run start

Generate a new module (e.g., "users" module)

nest g module users

Generate a new controller inside the users module

nest g controller users

Generate a new service inside the users module

nest g service users

Generate a resource (combination of module, controller, and service)

nest g resource users

Generate a controller with specific routing (e.g., "auth" module)

nest g controller auth --path auth

Generate a provider (custom service)

nest g provider custom-provider

Generate a class (e.g., a utility class)

nest g class utils/logger

Generate an interface

nest g interface users/interfaces/user

Generate a guard (for route protection)

nest g guard auth

Generate a pipe (for validation or transformation)

nest g pipe validation

Generate an interceptor (for modifying request/response)

nest g interceptor logging

Generate a filter (for handling exceptions)

nest g filter exceptions

Serve the project (dev mode)

npm run start:dev

Serve the project with a specific port

npm run start -- --port=3001

Build the project (production)

npm run build

Test the application

npm run test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment