An open API service indexing awesome lists of open source software.

https://github.com/datvt243/nodejs-resume-api-ts

Learning Node.js Express, Project create resume API
https://github.com/datvt243/nodejs-resume-api-ts

api crud-application express joi-validation mongoose nodejs router typescript

Last synced: about 2 months ago
JSON representation

Learning Node.js Express, Project create resume API

Awesome Lists containing this project

README

          

# πŸ“„ Resume API - Backend (Updated)

Mα»™t α»©ng dα»₯ng API backend **hoΓ n chỉnh** để **quαΊ£n lΓ½ hα»“ sΖ‘ α»©ng viΓͺn (CV/Resume)** vα»›i **Redis rate limiting**, **token blacklist**, **PDF export**, **Winston logging**, vΓ  **Jest testing**.

**Version**: 1.0.0 | **Author**: DatVT | **License**: ISC

---

## 🎯 Features

- πŸ” **Authentication**: JWT (access/refresh), Bcrypt, Token Blacklist (Redis)
- πŸ‘€ **Profile**: Candidate info + General (skills, languages, career)
- πŸ“š **Education** / πŸ’Ό **Experience** / πŸ† **Awards** / πŸ“œ **Certificates** / πŸš€ **Projects** / πŸ‘₯ **References**
- πŸ“„ **PDF Export** (Pug + PDFKit/Puppeteer)
- πŸ›‘οΈ **Rate Limiting** (Redis/mem fallback)
- πŸ“Š **Logging** (Winston daily)
- πŸ§ͺ **Tests** (Jest: auth/middlewares/utils/DB)
- βœ… **Health**: `/health` endpoint

## πŸ› οΈ Tech Stack

### Core

| Category | Tech |
| --------- | ---------------- |
| Runtime | Node.js |
| Framework | Express 4.19.2 |
| Language | TypeScript 5.5.4 |

### Database & Cache

| Tech | Version | Purpose |
| ------------------ | ------- | ---------------------- |
| MongoDB + Mongoose | 8.4.0 | Data |
| Redis | 4.6.0 | Rate limit / Blacklist |

### Auth & Security

| Tech | Version | Purpose |
| ------------------ | ------- | ---------- |
| JWT | 9.0.2 | Tokens |
| Bcrypt | 5.1.1 | Passwords |
| express-rate-limit | 8.3.0 | Protection |

### Utils

| Tech | Version | Purpose |
| -------------------- | -------------- | ---------- |
| Joi | 17.13.1 | Validation |
| PDFKit/Puppeteer/Pug | 0.15/22.13/3.0 | PDF |
| Winston | 3.19.0 | Logging |

---

## πŸ“ Project Structure

```
backend/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ server.ts (health/Redis)
β”‚ β”œβ”€β”€ config/ (env/Joi/CORS)
β”‚ β”œβ”€β”€ database/ (Mongo)
β”‚ β”œβ”€β”€ middlewares/ (rateLimit/logger)
β”‚ β”œβ”€β”€ models/ (schemas)
β”‚ β”œβ”€β”€ routers/api/v1/ (CRUD routes)
β”‚ β”œβ”€β”€ candidate_profile/ (controllers/services per section)
β”‚ β”œβ”€β”€ services/ (PDF/Redis)
β”‚ β”œβ”€β”€ utils/ (JWT/bcrypt/blacklist)
β”‚ β”œβ”€β”€ views/ (Pug)
β”‚ β”œβ”€β”€ public/ (assets/pdf)
β”‚ β”œβ”€β”€ __tests__/ (Jest)
β”‚ └── types/
β”œβ”€β”€ scripts/ (GitHub automation)
β”œβ”€β”€ TODO.md (progress)
β”œβ”€β”€ package.json
└── README.md ← Updated
```

---

## πŸš€ Quick Start

1. **Install**: `npm install`
2. **Env**: `npm run env:setup` + edit `.env`:

```
NODE_ENV=development
LOCAL_PORT=3001
MONGO_URI=... or MONGOBD_USER/PASSWORD
TOKEN_SECRET=... (32+ chars)
TOKEN_REFRESH=...
SESSION_SECRET=...
REDIS_URL=redis://localhost:6379 # Optional
```

3. **Redis** (rec.): `brew install redis && redis-server`
4. **Dev**: `npm run dev` β†’ http://localhost:3001/health
5. **Build/Test**: `npm run build` / `npm test`

**Prod**: `npm run start`

---

## πŸ“š API Endpoints (v1 - JWT required except auth)

### Auth `/api/v1/auth`

| Method | Path | Desc |
| ------ | ----------- | --------------- |
| POST | `/register` | Create user |
| POST | `/login` | Get tokens |
| POST | `/logout` | Blacklist token |
| POST | `/refresh` | Renew access |

### Candidate `/api/v1/candidate`

| Method | Path | Desc |
| --------- | --------- | ----------- |
| GET | `/:email` | Get profile |
| PUT/PATCH | `/` | Update |

### CRUD Pattern (all sections)

**Paths**: `/api/v1/{education,experience,award,certificate,project,reference,generalInformation}`
| Method | Path | Desc |
|--------|------|------|
| GET | `/` | List |
| POST | `/create` | Create |
| PUT | `/update` | Update |
| DELETE | `/delete/:id` | Delete |

**Header**: `Authorization: Bearer `

---

## πŸ” Auth Flow

1. **Login** β†’ `{token, tokenRefresh}`
2. **API Calls**: `Authorization: Bearer ${token}`
3. **Refresh**: POST `/auth/refresh`
4. **Logout**: Blacklist (Redis/utils/tokenBlacklist.ts)
5. **Invalid**: Checked via Redis/mem store

---

## πŸ§ͺ Scripts & Testing

**Scripts**:

- `npm run dev` - Hot reload
- `npm run build` - Compile + copy assets
- `npm run test` - Jest

**Tests (~20 files)**: auth.service/controller, middlewares (rateLimit/logger/verify), utils (bcrypt/valid), database/mongo

---

---

## πŸ›‘οΈ Production Notes

- **Rate Limit**: Redis (fallback mem), exempt `/health`
- **Blacklist**: Redis/utils/tokenBlacklist.ts
- **Logs**: Winston daily rotation
- **Static**: public/ (CSS/JS/fonts/img/PDFs)
- **PDF**: services/createPDF.ts + views/

---

## πŸ› Troubleshooting

| Issue | Fix |
| ------------ | ------------------------------------ |
| Mongo fail | MONGO*URI or MONGOBD*\* vars |
| Redis fail | `brew install redis` or mem fallback |
| JWT invalid | Token expired/blacklisted |
| Rate limited | Wait / check Redis |
| Build fail | `npm run copy` |
| Logs | Check `logs/` (Winston) |

---

## πŸ“ž Support

Để bΓ‘o cΓ‘o bug hoαΊ·c đề xuαΊ₯t tΓ­nh nΔƒng, vui lΓ²ng tαΊ‘o issue trΓͺn repository.

---

## πŸ‘¨β€πŸ’» Author

**Đẑt Vá** - [github.com/datvt243](https://github.com/datvt243)