express-ts-api-starter 1.0.1 โ 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +387 -495
- package/package.json +564 -160
package/README.md
CHANGED
|
@@ -1,495 +1,387 @@
|
|
|
1
|
-
# ๐๏ธ EXPRESS-TS-API-STARTER
|
|
2
|
-
|
|
3
|
-
[](https://badge.fury.io/js/express-ts-api-starter)
|
|
4
|
-
[](https://www.npmjs.com/package/express-ts-api-starter)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://www.typescriptlang.org/)
|
|
7
|
-
[](https://expressjs.com/)
|
|
8
|
-
[](https://nodejs.org/)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
- **
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
**
|
|
320
|
-
|
|
321
|
-
-
|
|
322
|
-
-
|
|
323
|
-
-
|
|
324
|
-
-
|
|
325
|
-
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
-
|
|
372
|
-
-
|
|
373
|
-
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
"response": { "data": "..." }
|
|
389
|
-
}
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
### Error Response
|
|
393
|
-
|
|
394
|
-
```json
|
|
395
|
-
{
|
|
396
|
-
"success": false,
|
|
397
|
-
"requestId": "550e8400-e29b-41d4-a716-446655440000",
|
|
398
|
-
"error": "Error message"
|
|
399
|
-
}
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
---
|
|
403
|
-
|
|
404
|
-
## ๐ฆ Graceful Shutdown
|
|
405
|
-
|
|
406
|
-
The server handles graceful shutdown on:
|
|
407
|
-
|
|
408
|
-
- `SIGTERM` (Docker stop)
|
|
409
|
-
- `SIGINT` (Ctrl+C)
|
|
410
|
-
|
|
411
|
-
Existing connections are completed before exit (30-second timeout).
|
|
412
|
-
|
|
413
|
-
---
|
|
414
|
-
|
|
415
|
-
---
|
|
416
|
-
|
|
417
|
-
## ๐ค Contributing
|
|
418
|
-
|
|
419
|
-
Contributions are welcome! Please:
|
|
420
|
-
|
|
421
|
-
1. Fork the repository
|
|
422
|
-
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
423
|
-
3. Commit changes (`git commit -m 'Add amazing feature'`)
|
|
424
|
-
4. Push to branch (`git push origin feature/amazing-feature`)
|
|
425
|
-
5. Open a Pull Request
|
|
426
|
-
|
|
427
|
-
---
|
|
428
|
-
|
|
429
|
-
## ๐ License
|
|
430
|
-
|
|
431
|
-
This project is licensed under the **MIT License** - see `LICENSE` file for details.
|
|
432
|
-
|
|
433
|
-
Free for personal and commercial use! โจ
|
|
434
|
-
|
|
435
|
-
---
|
|
436
|
-
|
|
437
|
-
## ๐ฏ Roadmap
|
|
438
|
-
|
|
439
|
-
- [ ] API Documentation (Swagger/OpenAPI)
|
|
440
|
-
- [ ] Health check endpoint
|
|
441
|
-
- [ ] Pagination utility
|
|
442
|
-
- [ ] Redis caching layer
|
|
443
|
-
- [ ] Database migrations
|
|
444
|
-
- [ ] Docker & Docker Compose
|
|
445
|
-
- [ ] CI/CD pipeline examples
|
|
446
|
-
- [ ] More comprehensive test suite
|
|
447
|
-
|
|
448
|
-
---
|
|
449
|
-
|
|
450
|
-
## ๐ฌ Questions & Support
|
|
451
|
-
|
|
452
|
-
- **Email**: nikhil.pk.connect@gmail.com
|
|
453
|
-
- **GitHub Issues**: [Report bugs](https://github.com/nikhilpktcr/express-ts-api-starter/issues)
|
|
454
|
-
- **GitHub**: [@nikhilpktcr](https://github.com/nikhilpktcr)
|
|
455
|
-
|
|
456
|
-
---
|
|
457
|
-
|
|
458
|
-
## ๐ Show Your Support
|
|
459
|
-
|
|
460
|
-
If this boilerplate helps your project:
|
|
461
|
-
|
|
462
|
-
- โญ **Star the repository** on GitHub
|
|
463
|
-
- ๐ฆ **Use the npm package** in your projects
|
|
464
|
-
- ๐ **Report issues** you encounter
|
|
465
|
-
- ๐ก **Suggest features** and improvements
|
|
466
|
-
- ๐ **Share** with other developers
|
|
467
|
-
|
|
468
|
-
Your support helps improve this project for everyone!
|
|
469
|
-
|
|
470
|
-
---
|
|
471
|
-
|
|
472
|
-
## ๐ Trending Keywords
|
|
473
|
-
|
|
474
|
-
This boilerplate is perfect for developers searching for:
|
|
475
|
-
|
|
476
|
-
- Express TypeScript starter
|
|
477
|
-
- Node.js REST API boilerplate
|
|
478
|
-
- Production-ready backend template
|
|
479
|
-
- MVC Node.js project
|
|
480
|
-
- TypeScript Express API
|
|
481
|
-
- MongoDB Express starter
|
|
482
|
-
- Secure Node.js backend
|
|
483
|
-
- Express authentication template
|
|
484
|
-
|
|
485
|
-
---
|
|
486
|
-
|
|
487
|
-
## ๐ Ready to Build?
|
|
488
|
-
|
|
489
|
-
Start building your next API with this production-ready boilerplate. Clone, customize, and deploy in minutes!
|
|
490
|
-
|
|
491
|
-
```bash
|
|
492
|
-
npm install express-ts-api-starter
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
**Happy coding!** ๐
|
|
1
|
+
# ๐๏ธ EXPRESS-TS-API-STARTER
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/express-ts-api-starter)
|
|
4
|
+
[](https://www.npmjs.com/package/express-ts-api-starter)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://expressjs.com/)
|
|
8
|
+
[](https://nodejs.org/)
|
|
9
|
+
|
|
10
|
+
> **Opinionated Express + TypeScript starter with JWT authentication, MongoDB integration, comprehensive security middleware, input validation, error handling, and production-ready architectureโget your REST API running in minutes, not hours.**
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## ๐ Quick Demo
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// Your API is ready with authentication, validation, and error handling out of the box!
|
|
18
|
+
import app from 'express-ts-api-starter';
|
|
19
|
+
|
|
20
|
+
// Start building your endpoints immediately
|
|
21
|
+
app.get('/api/v1/users', (req, res) => {
|
|
22
|
+
// Request ID automatically attached: req.headers['x-request-id']
|
|
23
|
+
// Error handling: Global middleware catches all errors
|
|
24
|
+
// Validation: Built-in express-validator ready
|
|
25
|
+
res.json({ message: 'API is running!' });
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ๐ Quick Start
|
|
32
|
+
|
|
33
|
+
### Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install express-ts-api-starter
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Launch Your Project
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Clone the repository
|
|
43
|
+
git clone https://github.com/nikhilpktcr/express-ts-starter.git my-api
|
|
44
|
+
cd my-api
|
|
45
|
+
|
|
46
|
+
# Install dependencies
|
|
47
|
+
npm install
|
|
48
|
+
|
|
49
|
+
# Copy environment variables
|
|
50
|
+
cp .env.example .env
|
|
51
|
+
|
|
52
|
+
# Start development server (hot reload enabled)
|
|
53
|
+
npm run dev
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**That's it!** Your server is running at `http://localhost:5000` with:
|
|
57
|
+
- โ
JWT authentication ready
|
|
58
|
+
- โ
MongoDB connection configured
|
|
59
|
+
- โ
Security middleware active
|
|
60
|
+
- โ
Request logging enabled
|
|
61
|
+
- โ
Error handling in place
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## โก Why Choose This Over Others?
|
|
66
|
+
|
|
67
|
+
### vs. Bare Express Setup
|
|
68
|
+
|
|
69
|
+
| Feature | Bare Express | express-ts-api-starter |
|
|
70
|
+
|---------|-------------|------------------------|
|
|
71
|
+
| **Setup Time** | 2-4 hours | **2 minutes** โก |
|
|
72
|
+
| **TypeScript** | Manual config | โ
Pre-configured |
|
|
73
|
+
| **Authentication** | Build from scratch | โ
JWT + bcryptjs ready |
|
|
74
|
+
| **Error Handling** | Manual try-catch | โ
Global middleware |
|
|
75
|
+
| **Request Logging** | Manual setup | โ
Morgan with request IDs |
|
|
76
|
+
| **Input Validation** | Manual validation | โ
express-validator integrated |
|
|
77
|
+
| **Security** | Manual headers | โ
Helmet + CORS configured |
|
|
78
|
+
| **Database** | Manual connection | โ
MongoDB/Mongoose ready |
|
|
79
|
+
| **Testing** | Manual Jest setup | โ
Jest configured with examples |
|
|
80
|
+
| **Code Quality** | No linting | โ
ESLint + Prettier ready |
|
|
81
|
+
| **Graceful Shutdown** | Not included | โ
Production-ready |
|
|
82
|
+
|
|
83
|
+
### vs. Other Starters
|
|
84
|
+
|
|
85
|
+
| Feature | Other Starters | express-ts-api-starter |
|
|
86
|
+
|---------|---------------|------------------------|
|
|
87
|
+
| **Architecture** | Varies | โ
**MVC with functional services** (clean, testable) |
|
|
88
|
+
| **Request Tracking** | Rare | โ
**Unique request IDs** (debugging made easy) |
|
|
89
|
+
| **Error Handling** | Basic | โ
**Comprehensive with graceful shutdown** |
|
|
90
|
+
| **Validation** | Optional | โ
**Built-in express-validator** |
|
|
91
|
+
| **Logging** | Basic | โ
**Morgan with request ID correlation** |
|
|
92
|
+
| **TypeScript** | Sometimes | โ
**100% TypeScript with strict mode** |
|
|
93
|
+
| **Documentation** | Minimal | โ
**Well-documented with examples** |
|
|
94
|
+
| **Testing** | Sometimes | โ
**Jest with test examples included** |
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## ๐ฏ Key Strengths
|
|
99
|
+
|
|
100
|
+
### ๐ **Authentication & Security**
|
|
101
|
+
- **JWT-based authentication** with secure token generation
|
|
102
|
+
- **bcryptjs password hashing** (industry standard)
|
|
103
|
+
- **Helmet.js** for HTTP security headers
|
|
104
|
+
- **CORS** configured for cross-origin requests
|
|
105
|
+
- **Rate limiting** ready to prevent DDoS attacks
|
|
106
|
+
- **Request ID tracking** for security auditing
|
|
107
|
+
|
|
108
|
+
### ๐ **Input Validation**
|
|
109
|
+
- **express-validator** middleware pre-configured
|
|
110
|
+
- **Type-safe validation** with TypeScript
|
|
111
|
+
- **Reusable validation rules** in dedicated validators folder
|
|
112
|
+
- **Automatic error responses** for invalid inputs
|
|
113
|
+
|
|
114
|
+
### ๐ก๏ธ **Error Handling**
|
|
115
|
+
- **Global error middleware** catches all errors
|
|
116
|
+
- **Standardized error responses** across all endpoints
|
|
117
|
+
- **Request ID included** in error responses for debugging
|
|
118
|
+
- **Graceful shutdown** handles SIGTERM/SIGINT properly
|
|
119
|
+
- **Uncaught exception handling** prevents crashes
|
|
120
|
+
|
|
121
|
+
### ๐ **Logging & Monitoring**
|
|
122
|
+
- **Morgan logging** with custom format
|
|
123
|
+
- **Request ID correlation** for tracking requests across services
|
|
124
|
+
- **Structured logging** ready for production monitoring
|
|
125
|
+
- **Error logging** with stack traces
|
|
126
|
+
|
|
127
|
+
### ๐๏ธ **Architecture**
|
|
128
|
+
- **MVC pattern** with clear separation of concerns
|
|
129
|
+
- **Functional service layer** (easier to test than classes)
|
|
130
|
+
- **Modular structure** - each feature is self-contained
|
|
131
|
+
- **Scalable design** - grow from startup to enterprise
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## ๐ฆ What's Included
|
|
136
|
+
|
|
137
|
+
### Core Features
|
|
138
|
+
|
|
139
|
+
- โ
**Express.js v5** - Latest framework version
|
|
140
|
+
- โ
**TypeScript 5.8** - Full type safety with strict mode
|
|
141
|
+
- โ
**MongoDB + Mongoose** - Database integration ready
|
|
142
|
+
- โ
**JWT Authentication** - Secure token-based auth
|
|
143
|
+
- โ
**bcryptjs** - Password hashing
|
|
144
|
+
- โ
**express-validator** - Input validation
|
|
145
|
+
- โ
**Helmet** - Security headers
|
|
146
|
+
- โ
**CORS** - Cross-origin resource sharing
|
|
147
|
+
- โ
**Morgan** - HTTP request logging
|
|
148
|
+
- โ
**Multer** - File upload support
|
|
149
|
+
- โ
**express-rate-limit** - Rate limiting
|
|
150
|
+
- โ
**Jest** - Testing framework with examples
|
|
151
|
+
- โ
**ESLint + Prettier** - Code quality tools
|
|
152
|
+
|
|
153
|
+
### Developer Experience
|
|
154
|
+
|
|
155
|
+
- โ
**Hot reload** - See changes instantly
|
|
156
|
+
- โ
**TypeScript declarations** - Full IntelliSense support
|
|
157
|
+
- โ
**Pre-configured scripts** - dev, build, test, lint
|
|
158
|
+
- โ
**Example code** - User module with CRUD operations
|
|
159
|
+
- โ
**Test examples** - Learn testing patterns
|
|
160
|
+
- โ
**Well-documented** - Clear code structure
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## ๐ Project Structure
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
src/
|
|
168
|
+
โโโ modules/ # Feature modules (MVC pattern)
|
|
169
|
+
โ โโโ users/
|
|
170
|
+
โ โโโ userController.ts # HTTP request handlers
|
|
171
|
+
โ โโโ userService.ts # Business logic
|
|
172
|
+
โ โโโ userMessage.ts # Constants/messages
|
|
173
|
+
โ โโโ tests/ # Unit tests
|
|
174
|
+
โโโ routes/ # API route definitions
|
|
175
|
+
โโโ middleware/ # Express middleware
|
|
176
|
+
โ โโโ auth.ts # JWT authentication
|
|
177
|
+
โ โโโ errorMiddleware.ts
|
|
178
|
+
โ โโโ validatorMiddleware.ts
|
|
179
|
+
โ โโโ requestIdMiddleware.ts
|
|
180
|
+
โโโ config/ # Configuration files
|
|
181
|
+
โ โโโ dbConfig.ts # MongoDB connection
|
|
182
|
+
โ โโโ envConfig.ts # Environment variables
|
|
183
|
+
โ โโโ rateLimitConfig.ts
|
|
184
|
+
โโโ models/ # Mongoose schemas
|
|
185
|
+
โโโ validators/ # Input validation rules
|
|
186
|
+
โโโ utils/ # Utility functions
|
|
187
|
+
โโโ types/ # TypeScript type definitions
|
|
188
|
+
โโโ app.ts # Express app setup
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## ๐ง Available Commands
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Development
|
|
197
|
+
npm run dev # Start dev server with hot reload
|
|
198
|
+
|
|
199
|
+
# Production
|
|
200
|
+
npm run build # Compile TypeScript to JavaScript
|
|
201
|
+
npm start # Start production server
|
|
202
|
+
|
|
203
|
+
# Testing
|
|
204
|
+
npm test # Run test suite
|
|
205
|
+
npm test -- --watch # Run tests in watch mode
|
|
206
|
+
npm test -- --coverage # Run with coverage report
|
|
207
|
+
|
|
208
|
+
# Code Quality
|
|
209
|
+
npm run lint # Check for linting errors
|
|
210
|
+
npm run lint:fix # Auto-fix linting errors
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## ๐ Configuration
|
|
216
|
+
|
|
217
|
+
### Environment Variables
|
|
218
|
+
|
|
219
|
+
Create a `.env` file:
|
|
220
|
+
|
|
221
|
+
```env
|
|
222
|
+
# Server
|
|
223
|
+
NODE_ENV=development
|
|
224
|
+
PORT=5000
|
|
225
|
+
BASIC_API_URL=/api/v1
|
|
226
|
+
|
|
227
|
+
# Database
|
|
228
|
+
DB_CONNECTION=mongodb://localhost:27017/
|
|
229
|
+
DB_NAME=testDB
|
|
230
|
+
|
|
231
|
+
# Authentication
|
|
232
|
+
JWT_SECRET=your-super-secret-jwt-key-change-in-production
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
See `.env.example` for all available options.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## ๐งช Testing
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Run all tests
|
|
243
|
+
npm test
|
|
244
|
+
|
|
245
|
+
# Watch mode
|
|
246
|
+
npm test -- --watch
|
|
247
|
+
|
|
248
|
+
# Coverage report
|
|
249
|
+
npm test -- --coverage
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Example test included in `src/modules/users/tests/userController.test.ts`
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## ๐ Standardized API Responses
|
|
257
|
+
|
|
258
|
+
All responses follow a consistent format:
|
|
259
|
+
|
|
260
|
+
**Success:**
|
|
261
|
+
```json
|
|
262
|
+
{
|
|
263
|
+
"success": true,
|
|
264
|
+
"requestId": "550e8400-e29b-41d4-a716-446655440000",
|
|
265
|
+
"message": "Operation successful",
|
|
266
|
+
"response": { "data": "..." }
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Error:**
|
|
271
|
+
```json
|
|
272
|
+
{
|
|
273
|
+
"success": false,
|
|
274
|
+
"requestId": "550e8400-e29b-41d4-a716-446655440000",
|
|
275
|
+
"error": "Error message"
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## ๐ Security Features
|
|
282
|
+
|
|
283
|
+
- **Helmet** - Sets secure HTTP headers
|
|
284
|
+
- **CORS** - Configurable cross-origin requests
|
|
285
|
+
- **JWT** - Secure token-based authentication
|
|
286
|
+
- **bcryptjs** - Password hashing (10 rounds)
|
|
287
|
+
- **Rate Limiting** - DDoS protection ready
|
|
288
|
+
- **Input Validation** - Prevents injection attacks
|
|
289
|
+
- **Request ID Tracking** - Security audit trail
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## ๐ฆ Production Ready
|
|
294
|
+
|
|
295
|
+
- โ
**Graceful shutdown** - Handles SIGTERM/SIGINT
|
|
296
|
+
- โ
**Error handling** - Global error middleware
|
|
297
|
+
- โ
**Logging** - Request tracking with unique IDs
|
|
298
|
+
- โ
**Type safety** - Full TypeScript coverage
|
|
299
|
+
- โ
**Testing** - Jest framework configured
|
|
300
|
+
- โ
**Code quality** - ESLint + Prettier
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## ๐ฏ Perfect For
|
|
305
|
+
|
|
306
|
+
- ๐ **REST APIs** - Full-featured API servers
|
|
307
|
+
- ๐ง **Microservices** - Scalable service architecture
|
|
308
|
+
- ๐ข **Enterprise Apps** - Production-ready foundation
|
|
309
|
+
- ๐ **Learning** - Best practices and patterns
|
|
310
|
+
- โก **MVPs** - Quick prototype development
|
|
311
|
+
- ๐ฑ **Backend Services** - Complex business logic
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## ๐ง Tech Stack
|
|
316
|
+
|
|
317
|
+
- **Runtime**: Node.js v20+
|
|
318
|
+
- **Framework**: Express.js v5
|
|
319
|
+
- **Language**: TypeScript 5.8
|
|
320
|
+
- **Database**: MongoDB with Mongoose
|
|
321
|
+
- **Security**: Helmet, CORS, JWT, bcryptjs
|
|
322
|
+
- **Validation**: express-validator
|
|
323
|
+
- **Logging**: Morgan
|
|
324
|
+
- **Testing**: Jest
|
|
325
|
+
- **Linting**: ESLint + Prettier
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## ๐ค Contributing
|
|
330
|
+
|
|
331
|
+
Contributions welcome! Please:
|
|
332
|
+
|
|
333
|
+
1. Fork the repository
|
|
334
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
335
|
+
3. Commit changes (`git commit -m 'Add amazing feature'`)
|
|
336
|
+
4. Push to branch (`git push origin feature/amazing-feature`)
|
|
337
|
+
5. Open a Pull Request
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## ๐ License
|
|
342
|
+
|
|
343
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
344
|
+
|
|
345
|
+
Free for personal and commercial use! โจ
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## ๐ฌ Support
|
|
350
|
+
|
|
351
|
+
- **Email**: nikhil.pk.connect@gmail.com
|
|
352
|
+
- **GitHub Issues**: [Report bugs](https://github.com/nikhilpktcr/express-ts-starter/issues)
|
|
353
|
+
- **GitHub**: [@nikhilpktcr](https://github.com/nikhilpktcr)
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## ๐ Show Your Support
|
|
358
|
+
|
|
359
|
+
If this boilerplate helps your project:
|
|
360
|
+
|
|
361
|
+
- โญ **Star the repository** on GitHub
|
|
362
|
+
- ๐ฆ **Use the npm package** in your projects
|
|
363
|
+
- ๐ **Report issues** you encounter
|
|
364
|
+
- ๐ก **Suggest features** and improvements
|
|
365
|
+
- ๐ **Share** with other developers
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## ๐ฏ Roadmap
|
|
370
|
+
|
|
371
|
+
- [ ] API Documentation (Swagger/OpenAPI)
|
|
372
|
+
- [ ] Health check endpoint
|
|
373
|
+
- [ ] Pagination utility
|
|
374
|
+
- [ ] Redis caching layer
|
|
375
|
+
- [ ] Docker & Docker Compose
|
|
376
|
+
- [ ] CI/CD pipeline examples
|
|
377
|
+
- [ ] More comprehensive test suite
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
**Ready to build?** Start your next API project in minutes:
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
npm install express-ts-api-starter
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
**Happy coding!** ๐
|