https://github.com/igorkrupenja/nestjs-starter
A simple NestJS starter with Prisma, Postgres — and 100% test coverage 🚀
https://github.com/igorkrupenja/nestjs-starter
backend nestjs nodejs prisma vitest
Last synced: 3 months ago
JSON representation
A simple NestJS starter with Prisma, Postgres — and 100% test coverage 🚀
- Host: GitHub
- URL: https://github.com/igorkrupenja/nestjs-starter
- Owner: IgorKrupenja
- Created: 2025-03-09T13:14:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-23T11:28:33.000Z (over 1 year ago)
- Last Synced: 2025-03-23T12:26:05.720Z (over 1 year ago)
- Topics: backend, nestjs, nodejs, prisma, vitest
- Language: TypeScript
- Homepage:
- Size: 506 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NestJS starter
## Description
NestJS starter project. Uses Postgres and Prisma ORM.
## Set up the project
This project requires a Node.js version specified in the `package.json` file. If you do not have it, the easiest option is to install [nvm](https://github.com/nvm-sh/nvm#installing-and-updating).
Run the following commands **or just the `./setup.sh` that will do this automatically** (and will also install `nvm` if it's missing). This script is especially useful if you are not a Node developer and do not have all the tools ready.
```bash
# Install the correct Node version
nvm install
# Install the correct pnpm version
corepack enable pnpm
corepack install
# Install dependencies
pnpm install
# Start DB
docker compose up db -d --wait
# Prepare Prisma
pnpm exec prisma migrate dev
pnpm exec prisma generate
pnpm exec prisma db seed
```
## Environment Variables
Environment-specific configuration files are located in the `config/` folder:
- `config/development.env` - Local development settings (with values)
- `config/production.env` - Production template (variable names only, values set via environment)
- `config/test.env` - Test environment settings (with values)
The application automatically loads the appropriate config file based on the `NODE_ENV` environment variable.
| Variable | Description | Required | Default Value | Recommended Production Value |
| --------------------------- | -------------------------------------------------------------------- | -------- | ---------------- | ------------------------------------------ |
| `DATABASE_URL` | PostgreSQL connection string | ✅ Yes | | |
| `LOGGER_LOG_LEVELS` | Comma-separated log levels (log, error, warn, debug, verbose, fatal) | | `error,warn,log` | `error,warn,log` |
| `LOGGER_COLORS` | Enable colored console output | | `false` | `false` |
| `API_DOCUMENTATION_ENABLED` | Enable Swagger API documentation | | `false` | `false` |
| `API_CORS_ORIGIN` | CORS allowed origins (can be comma-separated list) | | (empty string) | Configure based on your frontend domain(s) |
## Run the project
```bash
pnpm run dev
```
## Run tests
### Unit tests
```bash
# Unit tests in watch mode
pnpm run test
# Unit tests (run once)
pnpm run test:run
# Test coverage
pnpm run test:cov
```
### E2E tests
```bash
# Set up test database (starts container + runs migrations)
pnpm run test:e2e:setup
# E2E tests in watch mode
pnpm run test:e2e
# E2E tests (run once)
pnpm run test:e2e:run
```
**Note:** E2E tests use a separate PostgreSQL database (port 5433) for complete isolation from development data (port 5432).
## Lint
```bash
pnpm run lint
```
## Format
```bash
pnpm run format
```
## Swagger Documentation
Automatically generated API documentation can be found
at [http://localhost:3000/documentation](http://localhost:3000/documentation)
## Client Types
Run `pnpm generate-client-types` to regenerate `client/index.d.ts` from the OpenAPI spec.
## Testing Docker image
**You should NEVER use this to run locally**. This is only for testing the Docker image.
```bash
docker build -t nestjs-starter . --no-cache
docker run \
-p 3000:3000 \
-e DATABASE_URL="postgresql://postgres:postgres@host.docker.internal:5432/nestjs_starter?schema=starter" \
nestjs-starter
```