Skip to content
프로젝트

kentloog/nestjs-sequelize-typescript

GitHub에서 보기

소개

Nest + sequelize-typescript + JWT + Jest + Swagger

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Nest

NestJS + Sequelize + TypeScript starter

A starter kit demonstrating a modern NestJS REST API: JWT authentication, users and posts CRUD, schema migrations, Swagger docs, and a test setup with unit tests and self-contained e2e tests (Testcontainers — no local test database needed).

Tech stack

Prerequisites

  • Node.js >= 24 and npm >= 11 (.nvmrc is included — nvm use)
  • PostgreSQL >= 15 (recommended: 18) for local development
  • A Docker-compatible runtime (Docker Desktop, Colima, Podman, ...) — only needed for the e2e tests

Quick start

nvm use
npm install

# create the database and schema (defaults: postgres/postgres@localhost:5432, database "nest")
npm run db:create
npm run db:migrate

# optional: seed sample users
npm run db:seed-dev

# run in watch mode
npm run start:dev

The API is now available at http://localhost:3000 and the Swagger UI at http://localhost:3000/documentation.

Note: the application does not create or alter tables at startup — migrations are the single source of truth for the schema. Run npm run db:migrate after pulling changes that add migrations.

Configuration

All settings are environment variables with development defaults:

Variable Default (development) Description
NODE_ENV development production enables the production config
DATABASE_HOST localhost PostgreSQL host
DATABASE_PORT 5432 PostgreSQL port
DATABASE_USER postgres PostgreSQL user
DATABASE_PASSWORD postgres PostgreSQL password
DATABASE_DATABASE nest Database name
JWT_PRIVATE_KEY jwtPrivateKey Secret used to sign and verify JWTs — set a real secret in production
JWT_EXPIRES_IN 1d Token lifetime (e.g. 15m, 12h, 7d)

In production (NODE_ENV=production) there are no defaults — the DATABASE_* and JWT_* variables must be provided explicitly.

API overview

Method Endpoint Auth Description
POST /users/register — Register a new user, returns a JWT
POST /users/login — Log in, returns a JWT
GET /users Bearer List all users
GET /users/me Bearer Get the authenticated user
PUT /users/me Bearer Update the authenticated user
DELETE /users/me Bearer Delete the authenticated user
GET /posts — List all posts
GET /posts/:id — Get a single post
POST /posts Bearer Create a post
PUT /posts/:id Bearer Update your own post
DELETE /posts/:id Bearer Delete your own post

Register or log in to receive a token, then send it as Authorization: Bearer <token> (in Swagger UI: the Authorize button).

Testing

# unit tests
npm run test

# e2e tests (requires a running Docker daemon)
npm run test:e2e

# coverage
npm run test:cov

The e2e suite is fully self-contained: Testcontainers starts a throwaway PostgreSQL 18 container, runs the migrations against it, and removes it afterwards. No test database setup is required, and it works out of the box on GitHub Actions ubuntu runners.

All scripts

Script Description
npm run start / start:dev / start:debug Run the app (once / watch mode / debugger attached)
npm run build + npm run start:prod Compile to dist/ and run the compiled app
npm run test / test:watch / test:cov / test:debug Unit tests
npm run test:e2e End-to-end tests (Testcontainers)
npm run lint / lint:fix Lint (and auto-fix)
npm run format Format with Prettier
npm run db:create / db:drop Create / drop the database
npm run db:migrate Apply pending migrations
npm run db:seed-dev Seed development sample data
npm run db:reset Drop, recreate, migrate, and seed

Running in production

npm run build

NODE_ENV=production \
DATABASE_HOST=db.host.com \
DATABASE_PORT=5432 \
DATABASE_USER=user \
DATABASE_PASSWORD=pass \
DATABASE_DATABASE=database \
JWT_PRIVATE_KEY=<strong-secret> \
JWT_EXPIRES_IN=1d \
npm run start:prod

Remember to run the migrations against the production database as part of your deploy (npm run db:migrate with the same DATABASE_* environment variables).

License

MIT

관련 프로젝트 살펴보기

불러오는 중…