exp-node-server 1.1.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 (57) hide show
  1. package/README.md +180 -0
  2. package/bin/cli.js +41 -0
  3. package/package.json +32 -0
  4. package/src/createProject.js +58 -0
  5. package/src/generateModule.js +61 -0
  6. package/src/utils/controllerGenerator.js +70 -0
  7. package/src/utils/routeGenerator.js +27 -0
  8. package/src/utils/routeInjector.js +40 -0
  9. package/src/utils/schemaGenerator.js +11 -0
  10. package/src/utils/serviceGenerator.js +49 -0
  11. package/src/utils/swaggerGenerator.js +112 -0
  12. package/src/utils/swaggerInjector.js +52 -0
  13. package/src/utils/validateModuleName.js +17 -0
  14. package/src/utils/validateProjectName.js +15 -0
  15. package/src/utils/validationGenerator.js +13 -0
  16. package/src/utils.js +26 -0
  17. package/templates/mongoose/.env.example +23 -0
  18. package/templates/mongoose/package.json +45 -0
  19. package/templates/mongoose/readme.md +180 -0
  20. package/templates/mongoose/src/app/configs/index.ts +26 -0
  21. package/templates/mongoose/src/app/errors/castError.ts +23 -0
  22. package/templates/mongoose/src/app/errors/duplicateError.ts +26 -0
  23. package/templates/mongoose/src/app/errors/validationError.ts +25 -0
  24. package/templates/mongoose/src/app/errors/zodError.ts +20 -0
  25. package/templates/mongoose/src/app/middlewares/auth.ts +50 -0
  26. package/templates/mongoose/src/app/middlewares/global_error_handler.ts +69 -0
  27. package/templates/mongoose/src/app/middlewares/not_found_api.ts +10 -0
  28. package/templates/mongoose/src/app/middlewares/request_validator.ts +14 -0
  29. package/templates/mongoose/src/app/middlewares/uploader.ts +16 -0
  30. package/templates/mongoose/src/app/modules/auth/auth.controller.ts +125 -0
  31. package/templates/mongoose/src/app/modules/auth/auth.interface.ts +24 -0
  32. package/templates/mongoose/src/app/modules/auth/auth.route.ts +46 -0
  33. package/templates/mongoose/src/app/modules/auth/auth.schema.ts +19 -0
  34. package/templates/mongoose/src/app/modules/auth/auth.service.ts +306 -0
  35. package/templates/mongoose/src/app/modules/auth/auth.swagger.ts +214 -0
  36. package/templates/mongoose/src/app/modules/auth/auth.validation.ts +37 -0
  37. package/templates/mongoose/src/app/modules/user/user.controller.ts +17 -0
  38. package/templates/mongoose/src/app/modules/user/user.interface.ts +15 -0
  39. package/templates/mongoose/src/app/modules/user/user.route.ts +20 -0
  40. package/templates/mongoose/src/app/modules/user/user.schema.ts +22 -0
  41. package/templates/mongoose/src/app/modules/user/user.service.ts +22 -0
  42. package/templates/mongoose/src/app/modules/user/user.swagger.ts +75 -0
  43. package/templates/mongoose/src/app/modules/user/user.validation.ts +18 -0
  44. package/templates/mongoose/src/app/types/error.d.ts +10 -0
  45. package/templates/mongoose/src/app/types/index.d.ts +12 -0
  46. package/templates/mongoose/src/app/utils/JWT.ts +26 -0
  47. package/templates/mongoose/src/app/utils/app_error.ts +12 -0
  48. package/templates/mongoose/src/app/utils/catch_async.ts +13 -0
  49. package/templates/mongoose/src/app/utils/cloudinary.ts +66 -0
  50. package/templates/mongoose/src/app/utils/isAccountExist.ts +31 -0
  51. package/templates/mongoose/src/app/utils/mail_sender.ts +102 -0
  52. package/templates/mongoose/src/app/utils/manage_response.ts +24 -0
  53. package/templates/mongoose/src/app.ts +42 -0
  54. package/templates/mongoose/src/routes.ts +13 -0
  55. package/templates/mongoose/src/server.ts +18 -0
  56. package/templates/mongoose/src/swaggerOptions.ts +44 -0
  57. package/templates/mongoose/tsconfig.json +20 -0
@@ -0,0 +1,102 @@
1
+ import nodemailer from 'nodemailer';
2
+ import { configs } from '../configs';
3
+ type TMailContent = {
4
+ to: string,
5
+ subject: string,
6
+ textBody: string,
7
+ htmlBody: string,
8
+ name?: string
9
+ }
10
+
11
+ const transporter = nodemailer.createTransport({
12
+ host: "smtp.gmail.com",
13
+ port: 465,
14
+ secure: true, // true for 465, false for other ports
15
+ auth: {
16
+ user: configs.email.app_email!,
17
+ pass: configs.email.app_password!,
18
+ },
19
+ });
20
+
21
+ // ✅ Email Sender Function
22
+ const sendMail = async (payload: TMailContent) => {
23
+ const info = await transporter.sendMail({
24
+ from: 'info@digitalcreditai.com',
25
+ to: payload.to,
26
+ subject: payload.subject,
27
+ text: payload.textBody,
28
+ html: `
29
+ <!DOCTYPE html>
30
+ <html lang="en">
31
+
32
+ <head>
33
+ <meta charset="UTF-8">
34
+ <title>Welcome Email</title>
35
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
36
+ <style>
37
+ * {
38
+ margin: 0;
39
+ padding: 0;
40
+ box-sizing: border-box;
41
+ }
42
+
43
+ /* Fallback styles for unsupported clients (some email clients ignore <style> tags) */
44
+ @media only screen and (max-width: 600px) {
45
+ .container {
46
+ padding: 20px !important;
47
+ }
48
+
49
+ .btn {
50
+ padding: 12px 18px !important;
51
+ font-size: 16px !important;
52
+ }
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body
58
+ style="margin: 0; padding: 0; font-family: Arial, sans-serif;">
59
+
60
+ <div style="max-width: 600px; margin: 40px auto; background-color: #f4f4f4; padding: 40px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05);"
61
+ class="container">
62
+
63
+ <div style="font-size: 16px; color: #555555; line-height: 1.6;">
64
+ <p style="margin-bottom: 30px;">Hi <strong>${payload?.name || ""}</strong>,</p>
65
+
66
+ ${payload?.htmlBody}
67
+
68
+ <div
69
+ style=" margin-top: 60px; text-align: center;">
70
+
71
+ <img style="width: 50px; height: 50px; border-radius: 50%;"
72
+ src="https://imgs.search.brave.com/IZoN38NQxnIIuB1I9E70bW6q5OvbEtz68YaxTe1j-o0/rs:fit:860:0:0:0/g:ce/aHR0cHM6Ly9lbGVt/ZW50cy1yZXNpemVk/LmVudmF0b3VzZXJj/b250ZW50LmNvbS9l/bGVtZW50cy1jb3Zl/ci1pbWFnZXMvMjhi/NmVjMTQtMGMwOS00/NGY1LWE5NGUtNmIy/OTM5NTZkMDM2P3c9/NDMzJmNmX2ZpdD1z/Y2FsZS1kb3duJnE9/ODUmZm9ybWF0PWF1/dG8mcz04Mjc0OWYy/ZDUyMmJiM2NlMjNi/OWNhNjhlZmFhNjdk/MTg5OGI4NWIwNzBh/MjQ1NjM4NmI1ZmFj/NWVmNmM5ZTNl"
73
+ alt="">
74
+
75
+ <p style="font-size: 12px;">The Support Team</p>
76
+ <h3>Company Name</h3>
77
+ </div>
78
+ </div>
79
+ <p style="font-size: 14px; color: #999999; margin-top: 20px; margin-bottom: 10px; text-align: center;">
80
+ This is an automated message — please do not reply to this email.
81
+ <br>
82
+ If you need assistance, feel free to contact our support team.
83
+ <br><br>
84
+ Thank you for choosing us!
85
+ </p>
86
+
87
+ <hr>
88
+ <div style="text-align: center; font-size: 12px; color: #999999; margin-top: 20px;">
89
+ &copy; {{year}} Your Company. All rights reserved.
90
+ </div>
91
+
92
+ </div>
93
+ </body>
94
+
95
+ </html>
96
+
97
+ `,
98
+ });
99
+ return info
100
+ };
101
+
102
+ export default sendMail;
@@ -0,0 +1,24 @@
1
+ import { Response } from "express"
2
+ interface IResponse<T> {
3
+ success: boolean,
4
+ statusCode: number,
5
+ message: string,
6
+ data?: T,
7
+ meta?: {
8
+ page?: number,
9
+ limit?: number,
10
+ skip?: number,
11
+ total?: number
12
+ }
13
+ }
14
+
15
+ const manageResponse = <T>(res: Response, payload: IResponse<T>) => {
16
+ res.status(payload.statusCode).json({
17
+ success: payload.success,
18
+ message: payload.message,
19
+ data: payload.data || undefined || null,
20
+ meta: payload.meta || undefined || null
21
+ })
22
+ }
23
+
24
+ export default manageResponse
@@ -0,0 +1,42 @@
1
+ import cookieParser from 'cookie-parser';
2
+ import cors from 'cors';
3
+ import express, { Request, Response } from 'express';
4
+ import swaggerJSDoc from 'swagger-jsdoc';
5
+ import swaggerUi from "swagger-ui-express";
6
+ import globalErrorHandler from './app/middlewares/global_error_handler';
7
+ import notFound from './app/middlewares/not_found_api';
8
+ import appRouter from './routes';
9
+ import { swaggerOptions } from './swaggerOptions';
10
+
11
+ // define app
12
+ const app = express()
13
+ const swaggerSpec = swaggerJSDoc(swaggerOptions);
14
+ app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
15
+
16
+ // middleware
17
+ app.use(cors({
18
+ origin: ["http://localhost:3000"],
19
+ methods: ["GET", "POST", "PATCH", "DELETE", "PUT"],
20
+ credentials: true
21
+ }))
22
+ app.use(express.json({ limit: "100mb" }))
23
+ app.use(express.raw())
24
+ app.use(cookieParser())
25
+ app.use(express.urlencoded({ extended: true }));
26
+ app.use("/api", appRouter)
27
+
28
+ // stating point
29
+ app.get('/', (req: Request, res: Response) => {
30
+ res.status(200).json({
31
+ status: 'success',
32
+ message: 'Server is running successful !!',
33
+ data: null,
34
+ });
35
+ });
36
+
37
+ // global error handler
38
+ app.use(globalErrorHandler);
39
+ app.use(notFound);
40
+
41
+ // export app
42
+ export default app;
@@ -0,0 +1,13 @@
1
+ import { Router } from "express";
2
+ import authRoute from "./app/modules/auth/auth.route";
3
+ import userRoute from "./app/modules/user/user.route";
4
+
5
+ const appRouter = Router();
6
+
7
+ const moduleRoutes = [
8
+ { path: "/auth", route: authRoute },
9
+ { path: "/user", route: userRoute },
10
+ ];
11
+
12
+ moduleRoutes.forEach((route) => appRouter.use(route.path, route.route));
13
+ export default appRouter;
@@ -0,0 +1,18 @@
1
+ import mongoose from "mongoose";
2
+ import app from "./app";
3
+ import { configs } from "./app/configs/index";
4
+
5
+ async function main() {
6
+ try {
7
+ app.listen(configs.port, async () => {
8
+ await mongoose.connect(configs.db_url as string);
9
+ console.log(`Server is running on port ${configs.port}`);
10
+ });
11
+ } catch (error) {
12
+ console.error("Error starting server:", error);
13
+ }
14
+ }
15
+
16
+ main().catch((error) => {
17
+ console.error("Error in main function:", error);
18
+ });
@@ -0,0 +1,44 @@
1
+ import path from "path";
2
+ import { configs } from "./app/configs";
3
+ import { authSwaggerDocs } from "./app/modules/auth/auth.swagger";
4
+ import { userSwaggerDocs } from "./app/modules/user/user.swagger";
5
+
6
+ export const swaggerOptions = {
7
+ definition: {
8
+ openapi: "3.0.0",
9
+ info: {
10
+ title: "API Doc - Build with Express CLI",
11
+ version: "1.0.0-Mahid",
12
+ description: "Express API with auto-generated Swagger docs",
13
+ },
14
+ paths: {
15
+ ...authSwaggerDocs,
16
+ ...userSwaggerDocs,
17
+ },
18
+ servers:
19
+ configs.env === "production"
20
+ ? [{ url: "https://live-url.com" }, { url: "http://localhost:5000" }]
21
+ : [{ url: "http://localhost:5000" }, { url: "https://live-url.com" }],
22
+ components: {
23
+ securitySchemes: {
24
+ AuthorizationToken: {
25
+ type: "apiKey",
26
+ in: "header",
27
+ name: "Authorization",
28
+ description: "Put your accessToken here ",
29
+ },
30
+ },
31
+ },
32
+ security: [
33
+ {
34
+ AuthorizationToken: [],
35
+ },
36
+ ],
37
+ },
38
+ apis: [
39
+ path.join(
40
+ __dirname,
41
+ configs.env === "production" ? "./**/*.js" : "./**/*.ts",
42
+ ),
43
+ ],
44
+ };
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016",
4
+ "module": "commonjs",
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ "esModuleInterop": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ },
12
+ "include": [
13
+ "src/**/*.ts"
14
+ ],
15
+ "exclude": [
16
+ "node_modules",
17
+ "dist",
18
+ "build"
19
+ ]
20
+ }