Skip to content

Latest commit

 

History

History
191 lines (146 loc) · 6.14 KB

File metadata and controls

191 lines (146 loc) · 6.14 KB

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

Backend Application

This is the backend service for Fullstack Monorepo Starter project, built with NestJS and Prisma.

Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • PNPM package manager
  • PostgreSQL database

Installation

  1. From the root directory, install dependencies:
pnpm install
  1. Set up your environment variables:
cp .env.example .env

Edit the .env file with your database credentials and other configuration.

  1. Run database migrations:
pnpm prisma migrate dev
  1. Start the development server:
pnpm dev

The API will be available at http://localhost:3001

Development Guide

Project Structure

apps/backend/
├── src/
│   ├── modules/         # Feature modules
│   ├── common/          # Shared code
│   ├── config/          # Configuration
│   └── main.ts         # Application entry point
├── prisma/             # Database schema and migrations
└── test/              # Test files

Adding New Features

  1. Create a new module:
pnpm nest generate module features/your-feature
  1. Generate components:
pnpm nest generate controller features/your-feature
pnpm nest generate service features/your-feature

Database Management

  1. Update Prisma schema (packages/database/prisma/schema.prisma)
  2. Generate Prisma client:
pnpm prisma generate
  1. Create a migration:
pnpm prisma migrate dev --name your_migration_name

API Documentation

  • Swagger documentation is available at /api/docs when running in development mode
  • Keep API documentation up to date using Swagger decorators

Testing

# Unit tests
pnpm test

# E2E tests
pnpm test:e2e

# Test coverage
pnpm test:cov

Best Practices

  1. Follow NestJS architectural patterns
  2. Use DTOs for request/response validation
  3. Implement proper error handling
  4. Write unit tests for services
  5. Use guards for authentication/authorization
  6. Follow RESTful API conventions

Adding New Dependencies

  1. Add backend-specific dependencies:
pnpm add -w @nestjs/something
  1. Add development dependencies:
pnpm add -Dw @types/something

Environment Variables

Key environment variables needed:

  • DATABASE_URL: PostgreSQL connection string
  • JWT_SECRET: Secret for JWT tokens
  • PORT: API port (default: 3001)

Troubleshooting

  1. Database connection issues:

    • Verify PostgreSQL is running
    • Check database credentials in .env
    • Ensure migrations are up to date
  2. Prisma issues:

    • Run pnpm prisma generate after schema changes
    • Clear Prisma cache: pnpm prisma generate --force
  3. Module resolution errors:

    • Check import paths
    • Verify module is properly registered in app.module.ts

Deployment

For production deployment:

  1. Build the application:
pnpm build
  1. Start in production mode:
pnpm start:prod

For more deployment options, check the NestJS deployment documentation.

Resources

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.