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.
Files changed (2) hide show
  1. package/README.md +387 -495
  2. package/package.json +564 -160
package/README.md CHANGED
@@ -1,495 +1,387 @@
1
- # ๐Ÿ—๏ธ EXPRESS-TS-API-STARTER | Express TypeScript Boilerplate
2
-
3
- [![npm version](https://badge.fury.io/js/express-ts-api-starter.svg)](https://badge.fury.io/js/express-ts-api-starter)
4
- [![npm downloads](https://img.shields.io/npm/dm/express-ts-api-starter.svg)](https://www.npmjs.com/package/express-ts-api-starter)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue.svg)](https://www.typescriptlang.org/)
7
- [![Express.js](https://img.shields.io/badge/Express-5.1-green.svg)](https://expressjs.com/)
8
- [![Node.js](https://img.shields.io/badge/Node.js-20+-brightgreen.svg)](https://nodejs.org/)
9
- [![MongoDB](https://img.shields.io/badge/MongoDB-Ready-green.svg)](https://www.mongodb.com/)
10
-
11
- **The fastest way to build production-grade REST APIs, web servers, and backend services with Node.js, Express.js, and TypeScript.**
12
-
13
- A modern, enterprise-ready boilerplate featuring MVC architecture, JWT authentication, MongoDB integration, comprehensive security, input validation, testing setup, and developer-friendly tooling. Perfect for Node.js developers building scalable REST APIs, microservices, and web servers.
14
-
15
- ---
16
-
17
- ## ๐Ÿ“Œ What's Included? (Everything for Node.js API Development)
18
-
19
- This production-ready Express.js + TypeScript boilerplate includes everything Node.js developers need to build scalable REST APIs:
20
-
21
- | Feature | Details |
22
- | --------------------- | ----------------------------------------------------- |
23
- | **Architecture** | MVC pattern with functional service layer |
24
- | **Type Safety** | 100% TypeScript with strict type checking |
25
- | **Database** | MongoDB/Mongoose pre-configured and ready to use |
26
- | **Authentication** | JWT-based auth with bcryptjs password hashing |
27
- | **Validation** | Built-in input validation using express-validator |
28
- | **Security** | Helmet, CORS, rate limiting, and request ID tracking |
29
- | **Middleware Stack** | Error handling, logging, authentication, file uploads |
30
- | **Testing Framework** | Jest with unit test examples |
31
- | **Code Quality** | ESLint + Prettier configured for consistency |
32
- | **API Responses** | Standardized response format across endpoints |
33
- | **Request Tracking** | Unique request IDs for debugging and logging |
34
- | **Graceful Shutdown** | Proper signal handling for production deployments |
35
- | **Modular Structure** | Feature-based folder organization for scalability |
36
-
37
- ---
38
-
39
- ## ๐ŸŽฏ Why Developers Choose This Express Boilerplate?
40
-
41
- โœ… **Zero Configuration** - Ready to code in seconds
42
- โœ… **Production-Ready** - Enterprise-grade security & performance
43
- โœ… **Fully Typed** - Complete TypeScript support with perfect type inference
44
- โœ… **Industry Standards** - Follows Node.js, Express.js best practices
45
- โœ… **Scalable Architecture** - Grow from startup to enterprise
46
- โœ… **Well-Tested** - Jest testing suite with examples
47
- โœ… **Amazing DX** - Hot reload, linting, formatting, debugging tools included
48
- โœ… **MongoDB Ready** - Mongoose integration pre-configured
49
- โœ… **Secure by Default** - Authentication, validation, rate limiting built-in
50
- โœ… **Active Community** - Regular updates and support
51
-
52
- ---
53
-
54
- ## ๐Ÿ” Perfect For Node.js Developers Building...
55
-
56
- - **REST APIs** - Full-featured API servers with authentication and validation
57
- - **Microservices** - Scalable service architecture ready for production
58
- - **Web Servers** - Fast, secure HTTP servers for web applications
59
- - **Backend Services** - Complex business logic with clean separation of concerns
60
- - **Startups** - Quick MVP development with enterprise-grade foundation
61
- - **Enterprise Apps** - Scalable architecture for large teams
62
- - **Real-time Backends** - Socket.io integration ready
63
- - **Data APIs** - MongoDB integration for data management
64
- - **Learning** - Best practices and patterns for Node.js/Express.js
65
-
66
- ---
67
-
68
- ## ๐Ÿš€ Quick Start - Get Coding in Seconds
69
-
70
- ### Option 1: Install as npm Package (Recommended)
71
-
72
- ```bash
73
- npm install express-ts-api-starter
74
- ```
75
-
76
- ### Option 2: Clone & Customize
77
-
78
- ```bash
79
- git clone https://github.com/nikhilpktcr/express-ts-api-starter.git my-api
80
- cd my-api
81
- npm install
82
- npm run dev
83
- ```
84
-
85
- ---
86
-
87
- ## ๐Ÿ“ฆ Available Commands
88
-
89
- ```bash
90
- # Install dependencies
91
- npm install
92
-
93
- # Start development server (hot reload)
94
- npm run dev
95
-
96
- # Build for production
97
- npm run build
98
-
99
- # Start production server
100
- npm start
101
-
102
- # Run test suite
103
- npm test
104
-
105
- # Lint and fix code
106
- npm run lint
107
- npm run lint:fix
108
- ```
109
-
110
- ---
111
-
112
- ## ๐Ÿ“ Project Structure
113
-
114
- ```
115
- src/
116
- โ”œโ”€โ”€ modules/
117
- โ”‚ โ””โ”€โ”€ users/
118
- โ”‚ โ”œโ”€โ”€ userController.ts # Handles HTTP requests
119
- โ”‚ โ”œโ”€โ”€ userService.ts # Singleton service - business logic
120
- โ”‚ โ”œโ”€โ”€ userMessage.ts # Constants/messages
121
- โ”‚ โ””โ”€โ”€ tests/
122
- โ”‚ โ””โ”€โ”€ userController.test.ts
123
- โ”œโ”€โ”€ routes/
124
- โ”‚ โ”œโ”€โ”€ index.ts # Main API router
125
- โ”‚ โ””โ”€โ”€ usersRoute.ts # /users routes
126
- โ”œโ”€โ”€ middleware/ # Express middleware
127
- โ”‚ โ”œโ”€โ”€ auth.ts # Authentication
128
- โ”‚ โ”œโ”€โ”€ errorMiddleware.ts # Error handling
129
- โ”‚ โ”œโ”€โ”€ logMiddleware.ts # Request logging (Morgan)
130
- โ”‚ โ”œโ”€โ”€ validatorMiddleware.ts # Input validation
131
- โ”‚ โ”œโ”€โ”€ uploadMiddleware.ts # File uploads (Multer)
132
- โ”‚ โ””โ”€โ”€ requestIdMiddleware.ts # Request tracking
133
- โ”œโ”€โ”€ config/ # Configuration files
134
- โ”‚ โ”œโ”€โ”€ envConfig.ts # Environment variables
135
- โ”‚ โ”œโ”€โ”€ dbConfig.ts # MongoDB/Mongoose connection
136
- โ”‚ โ”œโ”€โ”€ emailConfig.ts # Email service config
137
- โ”‚ โ”œโ”€โ”€ rateLimitConfig.ts # Rate limiting rules
138
- โ”‚ โ””โ”€โ”€ throttleConfig.cjs # Throttle configuration
139
- โ”œโ”€โ”€ models/
140
- โ”‚ โ””โ”€โ”€ UserModel.ts # Mongoose User schema
141
- โ”œโ”€โ”€ validators/ # Input validators
142
- โ”‚ โ””โ”€โ”€ userValidators.ts # User validation rules
143
- โ”œโ”€โ”€ types/
144
- โ”‚ โ”œโ”€โ”€ index.ts # Exported types
145
- โ”‚ โ”œโ”€โ”€ userTypes.ts # User type definitions
146
- โ”‚ โ””โ”€โ”€ roleType.ts # Role type definitions
147
- โ”œโ”€โ”€ interfaces/
148
- โ”‚ โ””โ”€โ”€ userInterface.ts # User interfaces
149
- โ”œโ”€โ”€ utils/ # Utility functions
150
- โ”‚ โ”œโ”€โ”€ responseUtil.ts # Standardized API responses
151
- โ”‚ โ””โ”€โ”€ authFunction.ts # Authentication helpers
152
- โ”œโ”€โ”€ constants/ # Application constants
153
- โ”‚ โ””โ”€โ”€ index.ts
154
- โ”œโ”€โ”€ messages/ # Success/error messages
155
- โ”‚ โ””โ”€โ”€ index.ts
156
- โ”œโ”€โ”€ app.ts # Express app initialization
157
- โ””โ”€โ”€ server.ts # Server entry point
158
- ```
159
-
160
- ---
161
-
162
- ## โœจ Features
163
-
164
- - โœ… **Express + TypeScript** - Full type safety
165
- - โœ… **MVC Architecture** - Clean separation of concerns
166
- - โœ… **Functional Service Pattern** - Lightweight, testable business logic
167
- - โœ… **Modular Routing** - Feature-based structure
168
- - โœ… **Security** - Helmet, CORS, JWT, bcryptjs
169
- - โœ… **Database** - MongoDB with Mongoose integration
170
- - โœ… **Validation** - Express-validator middleware
171
- - โœ… **Error Handling** - Global error middleware + graceful shutdown
172
- - โœ… **Logging** - Morgan with request IDs
173
- - โœ… **File Uploads** - Multer configured
174
- - โœ… **Rate Limiting** - Express rate-limit ready
175
- - โœ… **Code Quality** - ESLint + Prettier
176
- - โœ… **Testing** - Jest configured
177
- - โœ… **Standardized Responses** - Consistent API responses
178
-
179
- ---
180
-
181
- ## ๐Ÿง  Architectural Patterns
182
-
183
- ### Pattern Overview
184
-
185
- | Pattern/Concept | Implementation |
186
- | -------------------------- | --------------------------------------------------- |
187
- | **MVC** | Controllers, Services, Models - clean separation |
188
- | **Functional Services** | Exported functions for business logic (not classes) |
189
- | **Modular Design** | Each feature is self-contained and independent |
190
- | **Separation of Concerns** | `app.ts` initializes app, `server.ts` starts server |
191
- | **Global Error Handling** | Centralized error middleware |
192
- | **Request Tracking** | Unique request IDs for debugging |
193
- | **Graceful Shutdown** | Proper signal handling (SIGTERM, SIGINT) |
194
-
195
- ### Why Functional Services Instead of Class-Based Singletons?
196
-
197
- This boilerplate uses **Functional Service Pattern** (exported async functions) instead of traditional Singleton classes. Here's why this approach is optimal:
198
-
199
- #### โœ… **Benefits for Developers**
200
-
201
- **1. Simplicity & Readability**
202
-
203
- ```typescript
204
- // โœจ Our approach - simple and direct
205
- export const registerUser = async (data) => { ... }
206
- export const loginUser = async (data) => { ... }
207
-
208
- // vs. Class-based singleton (boilerplate heavy)
209
- class UserService {
210
- private static instance: UserService;
211
- static getInstance() { ... }
212
- async registerUser() { ... }
213
- }
214
- ```
215
-
216
- **2. Easier Testing & Mocking**
217
-
218
- ```typescript
219
- // Functional - trivial to mock
220
- jest.mock("./userService", () => ({
221
- registerUser: jest.fn(),
222
- }));
223
-
224
- // Class singleton - requires getInstance() mocking
225
- ```
226
-
227
- **3. Tree-Shaking & Bundle Size**
228
-
229
- - Only imported functions are included in production builds
230
- - Class instantiation adds unnecessary overhead
231
- - Faster startup time
232
-
233
- **4. No State Management Issues**
234
-
235
- - Functional services are stateless โ†’ no singleton state pollution
236
- - Each request is isolated and independent
237
- - No threading/concurrency concerns
238
-
239
- **5. Better for Async Operations**
240
-
241
- ```typescript
242
- // Naturally async
243
- export const registerUser = async (data) => {
244
- // Direct async/await
245
- };
246
-
247
- // vs. Class requiring async getInstance()
248
- ```
249
-
250
- #### ๐ŸŽฏ **Robustness**
251
-
252
- โœ… **Testable** - Functions are pure and easy to mock
253
- โœ… **Scalable** - Add new services without complexity
254
- โœ… **Maintainable** - No hidden state or initialization logic
255
- โœ… **Production-Ready** - Used by companies like Airbnb, Stripe
256
- โœ… **TypeScript-Friendly** - Full type inference for functions
257
-
258
- #### ๐Ÿ“Š **Comparison**
259
-
260
- | Aspect | Functional | Class Singleton |
261
- | ------------------ | ----------------------- | ----------------- |
262
- | **Complexity** | Low | Medium-High |
263
- | **Testing** | Easy | Complex |
264
- | **Bundle Size** | Smaller | Larger |
265
- | **Learning Curve** | Minimal | Moderate |
266
- | **Scalability** | Linear | Logarithmic |
267
- | **Production Use** | Airbnb, Stripe, Netflix | Legacy enterprise |
268
-
269
- ---
270
-
271
- ## ๐Ÿ”ง Tech Stack
272
-
273
- - **Runtime**: [Node.js](https://nodejs.org/) (v20+)
274
- - **Framework**: [Express](https://expressjs.com/) v5
275
- - **Language**: [TypeScript](https://www.typescriptlang.org/) v5
276
- - **Database**: [MongoDB](https://www.mongodb.com/) with [Mongoose](https://mongoosejs.com/)
277
- - **Security**: [Helmet](https://helmetjs.github.io/), [CORS](https://github.com/expressjs/cors)
278
- - **Authentication**: [JWT](https://jwt.io/), [bcryptjs](https://github.com/dcodeIO/bcrypt.js)
279
- - **Validation**: [express-validator](https://express-validator.github.io/docs/)
280
- - **Logging**: [Morgan](https://github.com/expressjs/morgan)
281
- - **File Upload**: [Multer](https://github.com/expressjs/multer)
282
- - **Testing**: [Jest](https://jestjs.io/)
283
- - **Linting**: [ESLint](https://eslint.org/) + [Prettier](https://prettier.io/)
284
-
285
- ---
286
-
287
- ## ๐Ÿ“ Configuration
288
-
289
- ### Environment Variables
290
-
291
- Create a `.env` file in the root by copying from `.env.example`:
292
-
293
- ```bash
294
- cp .env.example .env
295
- ```
296
-
297
- Then update the values:
298
-
299
- ```env
300
- # Server
301
- NODE_ENV=development
302
- PORT=5000
303
- BASIC_API_URL=/api/v1
304
-
305
- # Database
306
- DB_CONNECTION=mongodb://localhost:27017/
307
- DB_NAME=testDB
308
-
309
- # Authentication
310
- JWT_SECRET=your-super-secret-jwt-key-change-in-production
311
-
312
- # Email (Optional)
313
- SMTP_HOST=smtp.gmail.com
314
- SMTP_PORT=587
315
- SMTP_USER=your-email@gmail.com
316
- SMTP_PASSWORD=your-app-password
317
- ```
318
-
319
- **Key Variables:**
320
-
321
- - `PORT` - Server port (default: 5000)
322
- - `DB_CONNECTION` - MongoDB connection string
323
- - `DB_NAME` - Database name
324
- - `JWT_SECRET` - Secret key for JWT tokens (โš ๏ธ Change in production!)
325
- - `BASIC_API_URL` - API base path (default: /api/v1)
326
-
327
- See [`.env.example`](.env.example) for complete list of options.
328
-
329
- ---
330
-
331
- ## ๐Ÿ” Security Features
332
-
333
- - **Helmet** - HTTP headers security
334
- - **CORS** - Cross-Origin Resource Sharing
335
- - **JWT** - Secure authentication
336
- - **bcryptjs** - Password hashing
337
- - **Rate Limiting** - DDoS protection
338
- - **Input Validation** - Prevent injection attacks
339
- - **Request ID Tracking** - Audit trail
340
-
341
- ---
342
-
343
- ## ๐Ÿงช Testing
344
-
345
- ```bash
346
- # Run all tests
347
- npm test
348
-
349
- # Run tests in watch mode
350
- npm test -- --watch
351
-
352
- # Run with coverage
353
- npm test -- --coverage
354
- ```
355
-
356
- ---
357
-
358
- ## ๐Ÿ”ข API Versioning
359
-
360
- Supports URL-based API versioning for backward compatibility.
361
-
362
- ```typescript
363
- // In app.ts
364
- app.use("/api/v1", routes); // Change version as needed
365
- ```
366
-
367
- **Example Endpoints:**
368
-
369
- - `POST /api/v1/users` - Create user
370
- - `GET /api/v1/users` - Get all users
371
- - `GET /api/v1/users/:id` - Get user by ID
372
- - `PUT /api/v1/users/:id` - Update user
373
- - `DELETE /api/v1/users/:id` - Delete user
374
-
375
- ---
376
-
377
- ## ๐Ÿ“‹ Standardized Responses
378
-
379
- All API responses follow a consistent format:
380
-
381
- ### Success Response
382
-
383
- ```json
384
- {
385
- "success": true,
386
- "requestId": "550e8400-e29b-41d4-a716-446655440000",
387
- "message": "Operation successful",
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
+ [![npm version](https://badge.fury.io/js/express-ts-api-starter.svg)](https://badge.fury.io/js/express-ts-api-starter)
4
+ [![npm downloads](https://img.shields.io/npm/dm/express-ts-api-starter.svg)](https://www.npmjs.com/package/express-ts-api-starter)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Express.js](https://img.shields.io/badge/Express-5.1-green.svg)](https://expressjs.com/)
8
+ [![Node.js](https://img.shields.io/badge/Node.js-20+-brightgreen.svg)](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!** ๐ŸŽ‰