A simple REST API for managing and activating promo codes. Built with Node.js, Express, TypeScript, and PostgreSQL.
- Create and manage promo codes with a discount, activation limit, and expiry date
- Activate a promo code with an email address
- Prevents duplicate activations — each email can activate a promo code only once
- Prevents activation if the code is expired or has reached its limit
- Node.js 18+
- PostgreSQL
git clone https://github.com/Musaye99/promo-api
cd promo-apinpm installCreate a .env file in the root:
DATABASE_URL="postgresql://user:password@localhost:5432/promodb"
npx prisma migrate devnpm run devServer runs on http://localhost:3000
POST /promo-codes
{
"code": "SAVE20",
"discount": 20,
"limit": 5,
"expiresAt": "2026-12-31"
}GET /promo-codes
GET /promo-codes/:code
POST /promo-codes/:code/activate
{
"email": "user@example.com"
}| Status | Meaning |
|---|---|
| 400 | Missing fields, code expired, or limit reached |
| 404 | Promo code not found |
| 409 | Code already exists or email already activated |
| 500 | Server error |
- Node.js + TypeScript
- Express
- Prisma
- PostgreSQL