- Node.js 18+
- MySQL 8+ running locally (or via Docker)
git clone <repo-url>
cd api
npm install
# copy .env and fill in your credentials (see step 2)
npx prisma migrate dev # applies ALL existing migrations in order + regenerates client
npm run start:devnpm installCreate a .env file in the project root (never commit this file):
DATABASE_URL="mysql://USER:PASSWORD@localhost:3306/john_db"
JWT_SECRET="your-secret-here"
PORT=3000Replace USER and PASSWORD with your MySQL credentials. The database john_db must exist before running migrations:
CREATE DATABASE john_db;Apply all pending migrations to the database:
npx prisma migrate devThis also regenerates the Prisma client automatically.
If you're setting up from scratch for the first time, this creates all tables.
If you only changed the schema without new migrations, regenerate the client manually:
npx prisma generate# Development with hot-reload
npm run start:dev
# Debug mode
npm run start:debug
# Production
npm run build
npm run start:prodThe API will be available at http://localhost:3000 (or the port defined in .env).
| Command | Description |
|---|---|
npx prisma migrate dev --name <name> |
Create and apply a new migration |
npx prisma migrate deploy |
Apply pending migrations (production) |
npx prisma generate |
Regenerate client after schema changes |
npx prisma studio |
Open visual DB browser at localhost:5555 |
npx prisma migrate reset |
Drop DB, re-run all migrations (dev only) |
npx prisma db pull |
Introspect existing DB and update schema |
Always use a descriptive name for migrations:
npx prisma migrate dev --name add-deleted-at-to-user
- Edit
prisma/schema.prisma - Run:
npx prisma migrate dev --name describe-your-change
- Commit both the schema change and the generated migration file together.
npm run test # Unit tests
npm run test:e2e # End-to-end tests
npm run test:cov # Coverage reportnpm run lint
npm run format