TemplatesTypescriptBackendExpressExpress MySQL TypeScript

Express MySQL TypeScript

Express REST API with MySQL, Prisma ORM, JWT authentication, Swagger docs, and Docker support.

Quick Start

npx tempora-cli init express-mysql my-app

Stack

  • Express 4
  • TypeScript 5
  • Prisma 5
  • MySQL 8
  • mysql2
  • JSON Web Tokens (jsonwebtoken)
  • Swagger UI (swagger-ui-express + swagger-jsdoc)
  • Docker + Docker Compose
  • Node.js 20

Docker is the easiest way to run this — it starts both the app and MySQL for you with one command.

Prerequisites

Steps

# 1. Start everything (MySQL + app)
docker compose up
 
# 2. On first run only — run migrations in a second terminal
docker exec express_mysql_app pnpm prisma migrate dev --name init
 
# 3. Visit the API docs
open http://localhost:3000/api/docs

To stop everything:

docker compose down

To stop and wipe the database:

docker compose down -v

Running Locally (Without Docker)

Prerequisites

  • Node.js 20+
  • pnpm
  • MySQL 8 running locally
pnpm install
cp .env.example .env
# Edit .env with your local MySQL credentials
pnpm prisma migrate dev --name init
pnpm dev

Server running at http://localhost:3000

API Docs (Swagger)

Once the server is running, visit:

http://localhost:3000/api/docs

You can test every endpoint directly from the browser — no extra tools needed.

Testing the API Manually

1. Sign up

curl -X POST http://localhost:3000/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{"name":"Jane","email":"jane@example.com","password":"secret123"}'

Copy the token from the response.

2. Login

curl -X POST http://localhost:3000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"jane@example.com","password":"secret123"}'

3. Create a Todo

curl -X POST http://localhost:3000/api/todos \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -d '{"title":"Buy groceries"}'

4. Get all Todos

curl http://localhost:3000/api/todos \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

5. Update a Todo

curl -X PUT http://localhost:3000/api/todos/1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -d '{"completed":true}'

6. Delete a Todo

curl -X DELETE http://localhost:3000/api/todos/1 \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

API Routes

Auth

MethodRouteAccess
POST/api/auth/signupPublic
POST/api/auth/loginPublic

Todos

MethodRouteAccess
GET/api/todosProtected
POST/api/todosProtected
PUT/api/todos/:idProtected
DELETE/api/todos/:idProtected

Environment Variables

See .env.example for all required variables.


Documentation: tempora.irbaye.com