Nest framework TypeScript starter repository.
- Node.js
>= 24.9 - pnpm — any recent version; it switches automatically to the version pinned in the
packageManagerfield.
$ pnpm installCopy the example file and adjust it to your needs:
$ cp .env.example .envAll variables are validated with class-validator at startup (see src/configuration/environment-variables.ts); a bad value prevents the application from booting. To add a new variable:
- Add it to
.env.example. - Declare it with decorators in
EnvironmentVariables. - Read it in the
configurationfactory (src/configuration/configuration.ts).
# development
$ pnpm start
# watch mode
$ pnpm start:dev
# production mode
$ pnpm start:prodThe application exposes a GET /health endpoint suitable for liveness and readiness probes. To wire the database into the health check, migrate it to @nestjs/terminus and use TypeOrmHealthIndicator.
The template ships with TypeORM connected to PostgreSQL (see src/database). Entities are loaded automatically (autoLoadEntities), and migrations run on application startup (migrationsRun in src/database/typeorm-options.ts).
A sampled domain (src/notes) demonstrates the end-to-end pattern: entity + migration + repository service + controller.
Migrations are executed with the TypeORM CLI against src/database/data-source.ts:
# generate a migration from entity changes
$ pnpm migration:generate -- ChangeSomething
# run pending migrations
$ pnpm migration:run
# revert the last migration
$ pnpm migration:revertWhen generating or running migrations, a local PostgreSQL instance (e.g. the postgres service from docker compose) must be reachable and DATABASE_* variables configured in .env.
Schema auto-sync from entities is available through DATABASE_SYNCHRONIZE=true for local experimentation only — migrations remain the source of truth and synchronize must stay disabled in production.
# build the image
$ docker compose build
# run it (postgres service included)
$ docker compose up# unit tests
$ pnpm test
# e2e tests
$ pnpm test:e2e
# test coverage (enforces thresholds from jest.config.ts)
$ pnpm test:covTests never need a live PostgreSQL: DatabaseModule.forRoot() swaps the real TypeORM data source for an in-memory mock repository setup (see src/database/mock-database.module.ts) when NODE_ENV=test, and services are tested against MockRepository via __tests__/mocks/repository.mock.ts.
# check lint
$ pnpm lint
# fix lint issues
$ pnpm lint:fix
# format with prettier
$ pnpm formatThis project is MIT licensed.
