@madhusha_99/exp-gen 1.0.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/bin/copyDir.js +37 -0
  4. package/bin/copyDir.js.map +1 -0
  5. package/bin/copyTemplates.js +44 -0
  6. package/bin/copyTemplates.js.map +1 -0
  7. package/bin/installDependencies.js +36 -0
  8. package/bin/installDependencies.js.map +1 -0
  9. package/bin/scaffoldProject.js +45 -0
  10. package/bin/scaffoldProject.js.map +1 -0
  11. package/bin/script.js +118 -0
  12. package/bin/script.js.map +1 -0
  13. package/bin/type/projectConfig.js +2 -0
  14. package/bin/type/projectConfig.js.map +1 -0
  15. package/package.json +56 -0
  16. package/src/templates/js/mongodb/app.js +42 -0
  17. package/src/templates/js/mongodb/configs/db.js +14 -0
  18. package/src/templates/js/mongodb/controllers/auth.controller.js +71 -0
  19. package/src/templates/js/mongodb/controllers/user.controller.js +27 -0
  20. package/src/templates/js/mongodb/default.env +4 -0
  21. package/src/templates/js/mongodb/middlewares/auth.middleware.js +64 -0
  22. package/src/templates/js/mongodb/models/user.model.js +13 -0
  23. package/src/templates/js/mongodb/package.json +29 -0
  24. package/src/templates/js/mongodb/repositories/user.repository.js +21 -0
  25. package/src/templates/js/mongodb/routes/auth.route.js +9 -0
  26. package/src/templates/js/mongodb/routes/user.route.js +24 -0
  27. package/src/templates/js/mongodb/services/user.service.js +50 -0
  28. package/src/templates/js/mongodb/utils/asyncHandler.js +5 -0
  29. package/src/templates/js/mongodb/utils/response.js +13 -0
  30. package/src/templates/js/mysql/.gitkeep +0 -0
  31. package/src/templates/js/none/app.js +32 -0
  32. package/src/templates/js/none/default.env +4 -0
  33. package/src/templates/js/none/package.json +23 -0
  34. package/src/templates/js/none/routes/api.route.js +9 -0
  35. package/src/templates/js/postgresql/.gitkeep +0 -0
  36. package/src/templates/js/sqlite/.gitkeep +0 -0
  37. package/src/templates/ts/mongodb/default.env +4 -0
  38. package/src/templates/ts/mongodb/package.json +34 -0
  39. package/src/templates/ts/mongodb/src/app.ts +45 -0
  40. package/src/templates/ts/mongodb/src/configs/db.ts +11 -0
  41. package/src/templates/ts/mongodb/src/controllers/auth.controller.ts +78 -0
  42. package/src/templates/ts/mongodb/src/controllers/user.controller.ts +31 -0
  43. package/src/templates/ts/mongodb/src/dtos/user.dto.ts +13 -0
  44. package/src/templates/ts/mongodb/src/interfaces/IUser.ts +8 -0
  45. package/src/templates/ts/mongodb/src/interfaces/express.d.ts +9 -0
  46. package/src/templates/ts/mongodb/src/middlewares/auth.middleware.ts +82 -0
  47. package/src/templates/ts/mongodb/src/models/user.model.ts +14 -0
  48. package/src/templates/ts/mongodb/src/repositories/user.repository.ts +22 -0
  49. package/src/templates/ts/mongodb/src/routes/auth.route.ts +9 -0
  50. package/src/templates/ts/mongodb/src/routes/user.route.ts +25 -0
  51. package/src/templates/ts/mongodb/src/services/user.service.ts +52 -0
  52. package/src/templates/ts/mongodb/src/utils/asyncHandler.ts +14 -0
  53. package/src/templates/ts/mongodb/src/utils/response.ts +18 -0
  54. package/src/templates/ts/mongodb/tsconfig.json +16 -0
  55. package/src/templates/ts/none/default.env +4 -0
  56. package/src/templates/ts/none/package.json +34 -0
  57. package/src/templates/ts/none/src/app.ts +40 -0
  58. package/src/templates/ts/none/src/routes/api.route.ts +10 -0
  59. package/src/templates/ts/none/tsconfig.json +16 -0
@@ -0,0 +1,22 @@
1
+ import { User } from "../models/user.model.js";
2
+ import { CreateUserDTO, UpdateUserDTO } from "../dtos/user.dto.js";
3
+
4
+ export const getAllUsers = async () => {
5
+ return await User.find({});
6
+ };
7
+
8
+ export const getUserById = async (id: string) => {
9
+ return await User.findById(id);
10
+ };
11
+
12
+ export const createUser = async (data: CreateUserDTO) => {
13
+ return await User.create(data);
14
+ };
15
+
16
+ export const updateUser = async (id: string, data: UpdateUserDTO) => {
17
+ return await User.findByIdAndUpdate(id, data, { new: true });
18
+ };
19
+
20
+ export const deleteUser = async (id: string) => {
21
+ return await User.findByIdAndDelete(id);
22
+ };
@@ -0,0 +1,9 @@
1
+ import { Router } from "express";
2
+ import { login, signup } from "../controllers/auth.controller.js";
3
+
4
+ const authRoutes = Router();
5
+
6
+ authRoutes.post("/login", login);
7
+ authRoutes.post("/signup", signup);
8
+
9
+ export default authRoutes;
@@ -0,0 +1,25 @@
1
+ import { Router } from "express";
2
+ import {
3
+ getUsers,
4
+ getUser,
5
+ createUser,
6
+ updateUser,
7
+ deleteUser,
8
+ } from "../controllers/user.controller.js";
9
+ import { protect } from "../middlewares/auth.middleware.js";
10
+ import { successResponse } from "../utils/response.js";
11
+ import type { Request, Response } from "express";
12
+
13
+ const userRoutes = Router();
14
+
15
+ userRoutes.get("/protected", protect, (req: Request, res: Response) => {
16
+ res.json(successResponse({ user: req.user }, "Protected route accessed"));
17
+ });
18
+
19
+ userRoutes.get("/users", getUsers);
20
+ userRoutes.get("/users/:id", protect, getUser);
21
+ userRoutes.post("/users", createUser);
22
+ userRoutes.put("/users/:id", updateUser);
23
+ userRoutes.delete("/users/:id", deleteUser);
24
+
25
+ export default userRoutes;
@@ -0,0 +1,52 @@
1
+ import * as userRepo from "../repositories/user.repository";
2
+ import { successResponse, errorResponse } from "../utils/response";
3
+ import type { HttpError } from "http-errors";
4
+ import { CreateUserDTO, UpdateUserDTO } from "../dtos/user.dto";
5
+
6
+ export const getUsers = async () => {
7
+ try {
8
+ const users = await userRepo.getAllUsers();
9
+ return successResponse(users, "Users fetched successfully");
10
+ } catch (err) {
11
+ return errorResponse(err as HttpError, "Failed to fetch users");
12
+ }
13
+ };
14
+
15
+ export const getUser = async (id: string) => {
16
+ try {
17
+ const user = await userRepo.getUserById(id);
18
+ if (!user) throw new Error("User not found");
19
+ return successResponse(user, "User fetched successfully");
20
+ } catch (err) {
21
+ return errorResponse(err as HttpError, "Failed to fetch user");
22
+ }
23
+ };
24
+
25
+ export const createNewUser = async (data: CreateUserDTO) => {
26
+ try {
27
+ const user = await userRepo.createUser(data);
28
+ return successResponse(user, "User created successfully");
29
+ } catch (err) {
30
+ return errorResponse(err as HttpError, "Failed to create user");
31
+ }
32
+ };
33
+
34
+ export const updateExistingUser = async (id: string, data: UpdateUserDTO) => {
35
+ try {
36
+ const user = await userRepo.updateUser(id, data);
37
+ if (!user) throw new Error("User not found");
38
+ return successResponse(user, "User updated successfully");
39
+ } catch (err) {
40
+ return errorResponse(err as HttpError, "Failed to update user");
41
+ }
42
+ };
43
+
44
+ export const deleteExistingUser = async (id: string) => {
45
+ try {
46
+ const user = await userRepo.deleteUser(id);
47
+ if (!user) throw new Error("User not found");
48
+ return successResponse(user, "User deleted successfully");
49
+ } catch (err) {
50
+ return errorResponse(err as HttpError, "Failed to delete user");
51
+ }
52
+ };
@@ -0,0 +1,14 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+
3
+ type AsyncHandler = (
4
+ req: Request,
5
+ res: Response,
6
+ next: NextFunction
7
+ ) => Promise<any>;
8
+
9
+ const asyncHandler =
10
+ (fn: AsyncHandler) => (req: Request, res: Response, next: NextFunction) => {
11
+ Promise.resolve(fn(req, res, next)).catch(next);
12
+ };
13
+
14
+ export default asyncHandler;
@@ -0,0 +1,18 @@
1
+ import type { HttpError } from "http-errors";
2
+
3
+ export const successResponse = <T>(data: T, message: string = "Success") => ({
4
+ status: 200,
5
+ success: true,
6
+ message,
7
+ data,
8
+ });
9
+
10
+ export const errorResponse = (
11
+ error?: HttpError | null,
12
+ message: string = "Error"
13
+ ) => ({
14
+ status: error?.status || 500,
15
+ success: false,
16
+ message,
17
+ error: error?.message || message,
18
+ });
@@ -0,0 +1,16 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ "target": "es2022",
6
+ "module": "esnext",
7
+ "rootDir": "./src",
8
+ "outDir": "./dist",
9
+ // "verbatimModuleSyntax": true,
10
+ // "esModuleInterop": true,
11
+ // "forceConsistentCasingInFileNames": true,
12
+ // "strict": true,
13
+ // "skipLibCheck": true,
14
+ "typeRoots": ["src/interfaces", "src/dtos", "./node_modules/@types"]
15
+ }
16
+ }
@@ -0,0 +1,4 @@
1
+ PORT=8000
2
+ MONGO_URL=mongodb://localhost:27017/express_api
3
+ JWT_SECRET=your_jwt_secret_here
4
+ JWT_EXPIRES_IN=1d
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "ts-none",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "app.js",
7
+ "scripts": {
8
+ "dev": "tsx watch src/app.ts",
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "ISC",
14
+ "dependencies": {
15
+ "bcryptjs": "^3.0.3",
16
+ "cors": "^2.8.6",
17
+ "dotenv": "^17.3.1",
18
+ "express": "^5.2.1",
19
+ "http-errors": "^2.0.1",
20
+ "jsonwebtoken": "^9.0.3",
21
+ "mongoose": "^9.3.1",
22
+ "morgan": "^1.10.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/bcryptjs": "^2.4.6",
26
+ "@types/cors": "^2.8.19",
27
+ "@types/express": "^5.0.6",
28
+ "@types/jsonwebtoken": "^9.0.10",
29
+ "@types/morgan": "^1.9.10",
30
+ "@types/node": "^25.5.0",
31
+ "tsx": "^4.21.0",
32
+ "typescript": "^5.9.3"
33
+ }
34
+ }
@@ -0,0 +1,40 @@
1
+ import express, { Request, Response, NextFunction } from "express";
2
+ import morgan from "morgan";
3
+ import createError from "http-errors";
4
+ import cors from "cors";
5
+ import dotenv from "dotenv";
6
+ import apiRoutes from "./src/routes/api.route";
7
+
8
+ dotenv.config({ quiet: true });
9
+ const PORT = process.env.PORT || 3000;
10
+
11
+ const app = express();
12
+
13
+ // Middlewares
14
+ app.use(cors());
15
+ app.use(express.json());
16
+ app.use(express.urlencoded({ extended: true }));
17
+ app.use(morgan("dev"));
18
+
19
+ // Routes
20
+ app.get("/", (_: Request, res: Response) =>
21
+ res.json({ message: "API is running 🚀" })
22
+ );
23
+ app.use("/api", apiRoutes); // user routes
24
+
25
+ // 404 handler
26
+ app.use((req: Request, res: Response, next: NextFunction) => {
27
+ next(createError.NotFound());
28
+ });
29
+
30
+ // Global error handler
31
+ app.use((err: any, req: Request, res: Response) => {
32
+ res.status(err.status || 500).json({
33
+ success: false,
34
+ message: err.message || "Internal Server Error",
35
+ });
36
+ });
37
+
38
+ app.listen(PORT, () => {
39
+ console.log(`🚀 Server running @ http://localhost:${PORT}`);
40
+ });
@@ -0,0 +1,10 @@
1
+ import { Router } from "express";
2
+ import type { Request, Response } from "express";
3
+
4
+ const router = Router();
5
+
6
+ router.get("/", async (req: Request, res: Response) => {
7
+ res.send({ message: "Ok api is working 🚀" });
8
+ });
9
+
10
+ export default router;
@@ -0,0 +1,16 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ "target": "es2022",
6
+ "module": "esnext",
7
+ "rootDir": "./src",
8
+ "outDir": "./dist",
9
+ // "verbatimModuleSyntax": true,
10
+ // "esModuleInterop": true,
11
+ // "forceConsistentCasingInFileNames": true,
12
+ // "strict": true,
13
+ // "skipLibCheck": true,
14
+ "typeRoots": ["src/interfaces", "src/dtos", "./node_modules/@types"]
15
+ }
16
+ }