express-project-builder 1.0.6 → 1.0.8

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 +102 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,7 @@ A powerful and professional [Express.js project generator CLI](https://www.npmjs
12
12
  - [Key Elements](#Key-Elements)
13
13
  - [Folder Structure](#Folder-Structure)
14
14
  - [Packages](#Packages)
15
+ - [Examples](#Examples)
15
16
 
16
17
  # [Quick Start](#Quick-Start)
17
18
 
@@ -171,3 +172,104 @@ my-test-project/
171
172
  - [ts-node-dev (2.0.0)](https://www.npmjs.com/package/ts-node-dev)
172
173
  - [typescript (5.9.2)](https://www.npmjs.com/package/typescript)
173
174
  - [typescript-eslint (8.43.0)](https://www.npmjs.com/package/typescript-eslint)
175
+
176
+ ## [Examples](#Examples)
177
+
178
+ - /src/app/builder/**MongooseQueryBuilder.ts** <br/>
179
+ A fluent API for building complex MongoDB queries with Mongoose. Simplifies dynamic query construction for search, filtering, sorting, pagination, and field selection in a chainable interface.
180
+
181
+ ```typescript
182
+ // In your controller/service:
183
+ import MongooseQueryBuilder from "../../builder/MongooseQueryBuilder";
184
+
185
+ // Extract query parameters from request (e.g., ?search=keyword&page=1&limit=10)
186
+ const { page, limit, sort, search, fields, ...filters } = req.query;
187
+
188
+ // Create a new query builder instance
189
+ const docQuery = new MongooseQueryBuilder(YourModel.find(), req.query)
190
+
191
+ // Search in specified text fields (e.g., name, description, category)
192
+ .search(["name", "description", "category"])
193
+
194
+ // Apply filters dynamically (e.g., status=active, category=tech)
195
+ .filter()
196
+
197
+ // Sort results (e.g., ?sort=name asc,sort=-createdAt desc)
198
+ .sort()
199
+
200
+ // Paginate results (e.g., ?page=1&limit=10)
201
+ .paginate()
202
+
203
+ // Select specific fields (e.g., ?fields=name,price,description)
204
+ .fields();
205
+
206
+ // Execute the query and get results
207
+ const result = await docQuery.modelQuery;
208
+
209
+ // Get pagination metadata (total count, page, limit, total pages)
210
+ const meta = await docQuery.countTotal();
211
+
212
+ // Return the results and metadata from service
213
+ return {
214
+ result,
215
+ meta,
216
+ };
217
+ ```
218
+
219
+ - /src/app/builder/**PrismaQueryBuilder.ts** <br/>
220
+ A fluent API for building complex SQL queries with Prisma. Simplifies dynamic query construction for search, filtering, sorting, pagination, and field selection in a chainable interface.
221
+
222
+ ```typescript
223
+ // In your controller/service:
224
+ import PrismaQueryBuilder from "../../builder/PrismaQueryBuilder";
225
+
226
+ // Extract query parameters from request (e.g., ?search=keyword&page=1&limit=10)
227
+ const { page, limit, sort, search, fields, ...filters } = req.query;
228
+
229
+ // Create a new query builder instance
230
+ const docQuery = new PrismaQueryBuilder(YourModel.find(), req.query)
231
+
232
+ // Search in specified text fields (e.g., name, description, category)
233
+ .search(["name", "description", "category"])
234
+
235
+ // Apply filters dynamically (e.g., status=active, category=tech)
236
+ .filter()
237
+
238
+ // Sort results (e.g., ?sort=name asc,sort=-createdAt desc)
239
+ .sort()
240
+
241
+ // Paginate results (e.g., ?page=1&limit=10)
242
+ .paginate()
243
+
244
+ // Select specific fields (e.g., ?fields=name,price,description)
245
+ .fields();
246
+
247
+ // Execute the query and get results
248
+ const result = await docQuery.modelQuery;
249
+
250
+ // Get pagination metadata (total count, page, limit, total pages)
251
+ const meta = await docQuery.countTotal();
252
+
253
+ // Return the results and metadata from service
254
+ return {
255
+ result,
256
+ meta,
257
+ };
258
+ ```
259
+
260
+ - /src/**config/index.ts** <br/> Central configuration file that manages environment variables and application settings. This file provides a structured way to access environment variables throughout the application.
261
+
262
+ ```typescript
263
+ // In config/index.ts
264
+ export default {
265
+ // ... other env configurations
266
+
267
+ // New Env file Setup after ensure your .env file same secret is declear.
268
+ your_another_env_secret: ensureEnv("YOUR_ANOTHER_ENV_SECRET"),
269
+ };
270
+
271
+ // Accessing the configuration in other files
272
+ import config from "../../config";
273
+
274
+ const your_another_env_secret = config.your_another_env_secret;
275
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-project-builder",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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",