express-project-builder 1.0.15 → 1.0.17
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 +80 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -423,3 +423,83 @@ router.get("/products", apiRateLimiter, ProductControllers.getAllProducts);
|
|
|
423
423
|
// Apply rate limiter globally to all API routes
|
|
424
424
|
app.use("/v1/api/", apiRateLimiter, routers);
|
|
425
425
|
```
|
|
426
|
+
|
|
427
|
+
- /src/middlewares/**validateRequest.ts** <br/>
|
|
428
|
+
Middleware for validating incoming requests using Zod schemas. It checks for required fields, data formats, and returns an error response if validation fails.
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
// In your route file
|
|
432
|
+
import validateRequest from "../../middlewares/validateRequest";
|
|
433
|
+
import { ProductValidation } from "../../app/models/product_validationZodSchema";
|
|
434
|
+
|
|
435
|
+
router.post(
|
|
436
|
+
"/create",
|
|
437
|
+
validateRequest(ProductValidation.createProduct_ValidationZodSchema),
|
|
438
|
+
ProductControllers.createProduct
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
// /src/app/models/product_validationZodSchema.ts
|
|
442
|
+
import { z } from "zod";
|
|
443
|
+
|
|
444
|
+
const createProduct_ValidationZodSchema = z.object({
|
|
445
|
+
body: z.object({
|
|
446
|
+
name: z.string({ required_error: "Name is required" }),
|
|
447
|
+
price: z.number({ required_error: "Price is required" }).positive(),
|
|
448
|
+
category: z.string().optional(),
|
|
449
|
+
}),
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
export const ProductValidation = {
|
|
453
|
+
createProduct_ValidationZodSchema,
|
|
454
|
+
};
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
- /src/**routers/index.ts** <br/>
|
|
458
|
+
Centralized router file for grouping and exporting all route modules.
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
// In your src/routers/index.ts
|
|
462
|
+
import { ProductRoutes } from "../modules/product/product_route";
|
|
463
|
+
|
|
464
|
+
// Define all route modules with their paths
|
|
465
|
+
const moduleRoutes = [
|
|
466
|
+
{
|
|
467
|
+
path: "/products",
|
|
468
|
+
route: ProductRoutes,
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
path: "/new-route",
|
|
472
|
+
route: NewRouteRoutes,
|
|
473
|
+
},
|
|
474
|
+
];
|
|
475
|
+
|
|
476
|
+
// Creating a New Route Group
|
|
477
|
+
// Create new route file: src/routers/new-route.ts
|
|
478
|
+
import { Router } from "express";
|
|
479
|
+
const newRouters = Router();
|
|
480
|
+
|
|
481
|
+
// Define routes for this group
|
|
482
|
+
const moduleRoutes = [
|
|
483
|
+
{
|
|
484
|
+
path: "/new-version",
|
|
485
|
+
route: newVersionRoutes,
|
|
486
|
+
},
|
|
487
|
+
];
|
|
488
|
+
|
|
489
|
+
// Register routes in this group
|
|
490
|
+
moduleRoutes.forEach((route) => {
|
|
491
|
+
newRouters.use(route.path, route.route);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
export default newRouters;
|
|
495
|
+
|
|
496
|
+
// Applying in app.ts:
|
|
497
|
+
import routers from "./routers";
|
|
498
|
+
import newRouters from "./routers/new-route";
|
|
499
|
+
|
|
500
|
+
// Apply main routes with version prefix
|
|
501
|
+
app.use("/v1/api", routers);
|
|
502
|
+
|
|
503
|
+
// Apply new route group with different version
|
|
504
|
+
app.use("/v2/api", newRouters);
|
|
505
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-project-builder",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "A powerful and professional Express.js project generator CLI that instantly scaffolds a production-ready backend with TypeScript, modular architecture, and built-in support for MongoDB (Mongoose) or PostgreSQL (Prisma). Includes authentication, error handling, rate limiting, file upload, caching, and utility functions—so you can focus on building features instead of boilerplate. Perfect for kickstarting your next Express.js API project with best practices and modern tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/bin/index.js",
|