exp-node-server 1.1.7 → 2.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 (181) hide show
  1. package/README.md +82 -20
  2. package/dist/cli.js +525 -0
  3. package/package.json +29 -9
  4. package/templates/mongoose/.dockerignore +10 -0
  5. package/templates/mongoose/.env.example +56 -7
  6. package/templates/mongoose/.prettierignore +3 -0
  7. package/templates/mongoose/.prettierrc +7 -0
  8. package/templates/mongoose/Dockerfile +33 -0
  9. package/templates/mongoose/_gitignore +32 -0
  10. package/templates/mongoose/docker-compose.yml +21 -0
  11. package/templates/mongoose/eslint.config.js +35 -0
  12. package/templates/mongoose/package-lock.json +6377 -0
  13. package/templates/mongoose/package.json +49 -10
  14. package/templates/mongoose/readme.md +85 -0
  15. package/templates/mongoose/src/app/configs/index.ts +178 -26
  16. package/templates/mongoose/src/app/errors/zodError.ts +16 -16
  17. package/templates/mongoose/src/app/lib/db.ts +18 -0
  18. package/templates/mongoose/src/app/lib/logger.ts +12 -0
  19. package/templates/mongoose/src/app/middlewares/auth.ts +48 -44
  20. package/templates/mongoose/src/app/middlewares/global_error_handler.ts +59 -65
  21. package/templates/mongoose/src/app/middlewares/not_found_api.ts +7 -7
  22. package/templates/mongoose/src/app/middlewares/rate_limiter.ts +153 -0
  23. package/templates/mongoose/src/app/middlewares/request_validator.ts +11 -10
  24. package/templates/mongoose/src/app/middlewares/uploader.ts +17 -13
  25. package/templates/mongoose/src/app/modules/account/account.controller.ts +156 -0
  26. package/templates/mongoose/src/app/modules/account/account.interface.ts +65 -0
  27. package/templates/mongoose/src/app/modules/account/account.route.ts +101 -0
  28. package/templates/mongoose/src/app/modules/account/account.schema.ts +97 -0
  29. package/templates/mongoose/src/app/modules/account/account.service.ts +422 -0
  30. package/templates/mongoose/src/app/modules/account/account.swagger.ts +278 -0
  31. package/templates/mongoose/src/app/modules/account/account.validation.ts +63 -0
  32. package/templates/mongoose/src/app/modules/profile/profile.controller.ts +17 -0
  33. package/templates/mongoose/src/app/modules/profile/profile.interface.ts +7 -0
  34. package/templates/mongoose/src/app/modules/profile/profile.route.ts +28 -0
  35. package/templates/mongoose/src/app/modules/profile/profile.schema.ts +13 -0
  36. package/templates/mongoose/src/app/modules/profile/profile.service.ts +28 -0
  37. package/templates/mongoose/src/app/modules/profile/profile.swagger.ts +34 -0
  38. package/templates/mongoose/src/app/modules/profile/profile.validation.ts +8 -0
  39. package/templates/mongoose/src/app/passport-js/index.ts +87 -0
  40. package/templates/mongoose/src/app/passport-js/oauth-state.ts +150 -0
  41. package/templates/mongoose/src/app/passport-js/providers.ts +258 -0
  42. package/templates/mongoose/src/app/passport-js/social-account.ts +141 -0
  43. package/templates/mongoose/src/app/queues/agenda.ts +24 -0
  44. package/templates/mongoose/src/app/queues/email.queue.ts +53 -0
  45. package/templates/mongoose/src/app/queues/index.ts +13 -0
  46. package/templates/mongoose/src/app/templates/otpEmailTemplate.ts +185 -0
  47. package/templates/mongoose/src/app/templates/resetPasswordEmailTemplate.ts +157 -0
  48. package/templates/mongoose/src/app/types/error.d.ts +7 -7
  49. package/templates/mongoose/src/app/types/express.d.ts +11 -0
  50. package/templates/mongoose/src/app/types/passport-oauth1.d.ts +51 -0
  51. package/templates/mongoose/src/app/utils/JWT.ts +38 -18
  52. package/templates/mongoose/src/app/utils/app_error.ts +10 -10
  53. package/templates/mongoose/src/app/utils/auth_cookie.ts +27 -0
  54. package/templates/mongoose/src/app/utils/catch_async.ts +8 -8
  55. package/templates/mongoose/src/app/utils/cloudinary.ts +26 -59
  56. package/templates/mongoose/src/app/utils/mail_sender.ts +26 -92
  57. package/templates/mongoose/src/app/utils/manage_response.ts +19 -19
  58. package/templates/mongoose/src/app/utils/otp.ts +20 -0
  59. package/templates/mongoose/src/app/utils/session.ts +55 -0
  60. package/templates/mongoose/src/app.ts +73 -42
  61. package/templates/mongoose/src/routes.ts +13 -13
  62. package/templates/mongoose/src/server.ts +38 -18
  63. package/templates/mongoose/src/swaggerOptions.ts +23 -23
  64. package/templates/mongoose/tests/app.test.ts +97 -0
  65. package/templates/mongoose/tests/global-setup.ts +15 -0
  66. package/templates/mongoose/tests/helpers/fixtures.ts +42 -0
  67. package/templates/mongoose/tests/routes/account.test.ts +614 -0
  68. package/templates/mongoose/tests/routes/profile.test.ts +95 -0
  69. package/templates/mongoose/tests/routes/social.test.ts +310 -0
  70. package/templates/mongoose/tests/setup.ts +25 -0
  71. package/templates/mongoose/tsconfig.json +16 -20
  72. package/templates/mongoose/vitest.config.ts +43 -0
  73. package/templates/prisma/.dockerignore +2 -0
  74. package/templates/prisma/.env.example +62 -6
  75. package/templates/prisma/.prettierignore +3 -0
  76. package/templates/prisma/.prettierrc +7 -0
  77. package/templates/prisma/.projectrc.json +1 -1
  78. package/templates/prisma/Dockerfile +21 -7
  79. package/templates/prisma/_gitignore +35 -0
  80. package/templates/prisma/docker-compose.yml +8 -7
  81. package/templates/prisma/eslint.config.js +35 -0
  82. package/templates/prisma/package-lock.json +7327 -0
  83. package/templates/prisma/package.json +47 -9
  84. package/templates/prisma/prisma/schema/account.schema.prisma +92 -10
  85. package/templates/prisma/prisma/schema/profile.schema.prisma +8 -3
  86. package/templates/prisma/prisma/schema/schema.prisma +1 -2
  87. package/templates/prisma/prisma.config.ts +5 -5
  88. package/templates/prisma/readme.md +81 -0
  89. package/templates/prisma/src/app/configs/index.ts +175 -26
  90. package/templates/prisma/src/app/errors/zodError.ts +16 -16
  91. package/templates/prisma/src/app/lib/logger.ts +12 -0
  92. package/templates/prisma/src/app/lib/prisma.ts +4 -6
  93. package/templates/prisma/src/app/middlewares/auth.ts +37 -16
  94. package/templates/prisma/src/app/middlewares/global_error_handler.ts +42 -35
  95. package/templates/prisma/src/app/middlewares/not_found_api.ts +7 -7
  96. package/templates/prisma/src/app/middlewares/rate_limiter.ts +124 -0
  97. package/templates/prisma/src/app/middlewares/request_validator.ts +4 -3
  98. package/templates/prisma/src/app/middlewares/uploader.ts +17 -13
  99. package/templates/prisma/src/app/modules/account/account.controller.ts +74 -34
  100. package/templates/prisma/src/app/modules/account/account.route.ts +68 -22
  101. package/templates/prisma/src/app/modules/account/account.service.ts +329 -309
  102. package/templates/prisma/src/app/modules/account/account.swagger.ts +167 -76
  103. package/templates/prisma/src/app/modules/account/account.validation.ts +41 -19
  104. package/templates/prisma/src/app/modules/profile/profile.controller.ts +4 -4
  105. package/templates/prisma/src/app/modules/profile/profile.route.ts +18 -12
  106. package/templates/prisma/src/app/modules/profile/profile.service.ts +11 -18
  107. package/templates/prisma/src/app/modules/profile/profile.swagger.ts +11 -11
  108. package/templates/prisma/src/app/modules/profile/profile.validation.ts +2 -2
  109. package/templates/prisma/src/app/passport-js/index.ts +87 -0
  110. package/templates/prisma/src/app/passport-js/oauth-state.ts +150 -0
  111. package/templates/prisma/src/app/passport-js/providers.ts +263 -0
  112. package/templates/prisma/src/app/passport-js/social-account.ts +147 -0
  113. package/templates/prisma/src/app/queues/boss.ts +8 -0
  114. package/templates/prisma/src/app/queues/email.queue.ts +56 -0
  115. package/templates/prisma/src/app/queues/index.ts +14 -0
  116. package/templates/prisma/src/app/queues/maintenance.queue.ts +30 -0
  117. package/templates/prisma/src/app/templates/otpEmailTemplate.ts +185 -0
  118. package/templates/prisma/src/app/templates/resetPasswordEmailTemplate.ts +157 -0
  119. package/templates/prisma/src/app/types/error.d.ts +7 -7
  120. package/templates/prisma/src/app/types/express.d.ts +11 -0
  121. package/templates/prisma/src/app/types/passport-oauth1.d.ts +51 -0
  122. package/templates/prisma/src/app/utils/JWT.ts +36 -17
  123. package/templates/prisma/src/app/utils/app_error.ts +10 -10
  124. package/templates/prisma/src/app/utils/auth_cookie.ts +27 -0
  125. package/templates/prisma/src/app/utils/catch_async.ts +8 -8
  126. package/templates/prisma/src/app/utils/cloudinary.ts +26 -59
  127. package/templates/prisma/src/app/utils/mail_sender.ts +26 -92
  128. package/templates/prisma/src/app/utils/manage_response.ts +19 -19
  129. package/templates/prisma/src/app/utils/otp.ts +20 -0
  130. package/templates/prisma/src/app/utils/session.ts +57 -0
  131. package/templates/prisma/src/app.ts +73 -42
  132. package/templates/prisma/src/routes.ts +12 -10
  133. package/templates/prisma/src/server.ts +37 -19
  134. package/templates/prisma/src/swaggerOptions.ts +22 -26
  135. package/templates/prisma/tests/app.test.ts +86 -0
  136. package/templates/prisma/tests/helpers/fixtures.ts +35 -0
  137. package/templates/prisma/tests/helpers/prisma.ts +32 -0
  138. package/templates/prisma/tests/routes/account.test.ts +627 -0
  139. package/templates/prisma/tests/routes/profile.test.ts +91 -0
  140. package/templates/prisma/tests/routes/social.test.ts +317 -0
  141. package/templates/prisma/tests/setup.ts +10 -0
  142. package/templates/prisma/tsconfig.json +16 -23
  143. package/templates/prisma/vitest.config.ts +38 -0
  144. package/bin/cli.js +0 -41
  145. package/src/createProject.js +0 -61
  146. package/src/generateModule.js +0 -93
  147. package/src/utils/getProjectType.js +0 -13
  148. package/src/utils/mongoose/controllerGenerator.js +0 -70
  149. package/src/utils/mongoose/routeGenerator.js +0 -27
  150. package/src/utils/mongoose/schemaGenerator.js +0 -11
  151. package/src/utils/mongoose/serviceGenerator.js +0 -49
  152. package/src/utils/mongoose/swaggerGenerator.js +0 -112
  153. package/src/utils/mongoose/validationGenerator.js +0 -13
  154. package/src/utils/prisma/prismaSchemaGenerator.js +0 -10
  155. package/src/utils/prisma/prismaServiceGenerator.js +0 -47
  156. package/src/utils/routeInjector.js +0 -40
  157. package/src/utils/swaggerInjector.js +0 -52
  158. package/src/utils/validateModuleName.js +0 -17
  159. package/src/utils/validateProjectName.js +0 -15
  160. package/src/utils.js +0 -26
  161. package/templates/mongoose/src/app/errors/castError.ts +0 -23
  162. package/templates/mongoose/src/app/errors/duplicateError.ts +0 -26
  163. package/templates/mongoose/src/app/errors/validationError.ts +0 -25
  164. package/templates/mongoose/src/app/modules/auth/auth.controller.ts +0 -127
  165. package/templates/mongoose/src/app/modules/auth/auth.interface.ts +0 -24
  166. package/templates/mongoose/src/app/modules/auth/auth.route.ts +0 -46
  167. package/templates/mongoose/src/app/modules/auth/auth.schema.ts +0 -19
  168. package/templates/mongoose/src/app/modules/auth/auth.service.ts +0 -324
  169. package/templates/mongoose/src/app/modules/auth/auth.swagger.ts +0 -214
  170. package/templates/mongoose/src/app/modules/auth/auth.validation.ts +0 -37
  171. package/templates/mongoose/src/app/modules/user/user.controller.ts +0 -17
  172. package/templates/mongoose/src/app/modules/user/user.interface.ts +0 -15
  173. package/templates/mongoose/src/app/modules/user/user.route.ts +0 -20
  174. package/templates/mongoose/src/app/modules/user/user.schema.ts +0 -22
  175. package/templates/mongoose/src/app/modules/user/user.service.ts +0 -22
  176. package/templates/mongoose/src/app/modules/user/user.swagger.ts +0 -75
  177. package/templates/mongoose/src/app/modules/user/user.validation.ts +0 -18
  178. package/templates/mongoose/src/app/types/index.d.ts +0 -12
  179. package/templates/mongoose/src/app/utils/isAccountExist.ts +0 -31
  180. package/templates/prisma/src/app/types/index.d.ts +0 -12
  181. package/templates/prisma/src/app/utils/otpGenerator.ts +0 -29
package/package.json CHANGED
@@ -1,19 +1,37 @@
1
1
  {
2
2
  "name": "exp-node-server",
3
- "version": "1.1.7",
3
+ "version": "2.0.0",
4
+ "description": "CLI to scaffold Express + TypeScript APIs with Mongoose or Prisma, Zod validation and Swagger docs",
4
5
  "type": "module",
5
6
  "bin": {
6
- "exp-node-server": "./bin/cli.js"
7
+ "exp-node-server": "./dist/cli.js"
7
8
  },
8
9
  "files": [
9
- "bin",
10
- "src",
11
- "templates"
10
+ "dist",
11
+ "templates",
12
+ "!templates/*/node_modules",
13
+ "!templates/*/dist",
14
+ "!templates/*/coverage",
15
+ "!templates/*/.env"
12
16
  ],
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "dev": "tsup --watch",
20
+ "typecheck": "tsc -p .",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
24
+ },
13
25
  "dependencies": {
14
- "chalk": "^5.3.0",
15
- "ora": "^7.0.1",
16
- "inquirer": "^9.2.7"
26
+ "@inquirer/select": "^5.2.6",
27
+ "chalk": "^5.6.2",
28
+ "ora": "^9.4.1"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^20.19.43",
32
+ "tsup": "^8.5.1",
33
+ "typescript": "^7.0.2",
34
+ "vitest": "^3.2.7"
17
35
  },
18
36
  "keywords": [
19
37
  "express",
@@ -28,7 +46,9 @@
28
46
  "exp-node",
29
47
  "server"
30
48
  ],
49
+ "author": "Abumahid (https://abumahid.me)",
50
+ "homepage": "https://www.npmjs.com/package/exp-node-server",
31
51
  "engines": {
32
- "node": ">=20.0.0"
52
+ "node": ">=20.17.0"
33
53
  }
34
54
  }
@@ -0,0 +1,10 @@
1
+ node_modules
2
+ npm-debug.log
3
+ Dockerfile
4
+ .git
5
+ .gitignore
6
+ README.md
7
+ .env
8
+ dist
9
+ docker-compose.ymltests
10
+ coverage
@@ -1,23 +1,72 @@
1
+ # Default Node config
1
2
  NODE_ENV=development
2
- DATABASE_URL=
3
3
  PORT=5000
4
+ # Number of reverse proxies in front of the app (1 behind Caddy/Nginx). Keep 0 if exposed directly.
5
+ TRUST_PROXY=0
4
6
 
7
+ # Database config (docker-compose starts MongoDB on localhost:27017)
8
+ DATABASE_URL="mongodb://localhost:27017/server_db"
5
9
 
6
10
  # JWT Configuration
11
+ # Each secret must be a different random value of 32+ characters: `openssl rand -hex 32`
7
12
  ACCESS_TOKEN=
8
- REFRESH_TOKEN=
9
- ACCESS_EXPIRES=
10
- REFRESH_EXPIRES=
11
- RESET_SECRET=
12
- RESET_EXPIRES=
13
+ # Access tokens are short-lived; refresh tokens (opaque, rotated on every use) last longer
14
+ ACCESS_EXPIRES=15m
15
+ REFRESH_EXPIRES_DAYS=30
13
16
  VERIFIED_TOKEN=
14
- FRONT_END_URL=
17
+ RESET_SECRET=
18
+ RESET_EXPIRES=15m
19
+ FRONT_END_URL=http://localhost:5173
20
+ # Comma separated list of allowed origins. Defaults to FRONT_END_URL.
21
+ CORS_ORIGINS=
15
22
 
16
23
  # Email Configuration
17
24
  APP_USER_EMAIL=
18
25
  APP_PASSWORD=
26
+ # "From" address. Defaults to APP_USER_EMAIL.
27
+ MAIL_FROM=
19
28
 
20
29
  # Cloudinary Configuration
21
30
  CLOUD_NAME=
22
31
  CLOUD_API_KEY=
23
32
  CLOUD_API_SECRET=
33
+
34
+ # Swagger Config (docs are disabled in production unless ENABLE_SWAGGER=true)
35
+ ENABLE_SWAGGER=
36
+ DEVELOPMENT_BASE_URL=http://localhost:5000
37
+ PRODUCTION_BASE_URL=
38
+
39
+ # Social login: set IS_<PROVIDER>_LOGIN=true and fill in its credentials.
40
+ # After the provider, the browser is sent here with `?code=` (trade it via
41
+ # POST /api/auth/social/exchange) or `?error=`. Defaults to FRONT_END_URL/auth/social/callback
42
+ SOCIAL_REDIRECT_URL=
43
+
44
+ IS_GOOGLE_LOGIN=false
45
+ GOOGLE_CLIENT_ID=
46
+ GOOGLE_CLIENT_SECRET=
47
+ GOOGLE_CALLBACK_URL=http://localhost:5000/api/auth/social/google/callback
48
+
49
+ IS_FACEBOOK_LOGIN=false
50
+ FACEBOOK_APP_ID=
51
+ FACEBOOK_APP_SECRET=
52
+ FACEBOOK_CALLBACK_URL=http://localhost:5000/api/auth/social/facebook/callback
53
+
54
+ IS_GITHUB_LOGIN=false
55
+ GITHUB_CLIENT_ID=
56
+ GITHUB_CLIENT_SECRET=
57
+ GITHUB_CALLBACK_URL=http://localhost:5000/api/auth/social/github/callback
58
+
59
+ IS_TWITTER_LOGIN=false
60
+ TWITTER_CONSUMER_KEY=
61
+ TWITTER_CONSUMER_SECRET=
62
+ TWITTER_CALLBACK_URL=http://localhost:5000/api/auth/social/twitter/callback
63
+
64
+ IS_LINKEDIN_LOGIN=false
65
+ LINKEDIN_CLIENT_ID=
66
+ LINKEDIN_CLIENT_SECRET=
67
+ LINKEDIN_CALLBACK_URL=http://localhost:5000/api/auth/social/linkedin/callback
68
+
69
+ IS_DISCORD_LOGIN=false
70
+ DISCORD_CLIENT_ID=
71
+ DISCORD_CLIENT_SECRET=
72
+ DISCORD_CALLBACK_URL=http://localhost:5000/api/auth/social/discord/callback
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ coverage
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "all",
6
+ "printWidth": 100
7
+ }
@@ -0,0 +1,33 @@
1
+ # ---------- BUILD STAGE ----------
2
+ FROM node:22-alpine AS builder
3
+
4
+ WORKDIR /app
5
+
6
+ # Only install deps first (cache friendly)
7
+ COPY package*.json ./
8
+ RUN npm ci
9
+
10
+ # Copy source + build
11
+ COPY . .
12
+ RUN npm run build
13
+
14
+
15
+ # ---------- PRODUCTION STAGE ----------
16
+ FROM node:22-alpine
17
+
18
+ WORKDIR /app
19
+
20
+ ENV NODE_ENV=production
21
+
22
+ # Only install production deps
23
+ COPY package*.json ./
24
+ RUN npm ci --omit=dev && npm cache clean --force
25
+
26
+ # Copy built app
27
+ COPY --from=builder /app/dist ./dist
28
+
29
+ USER node
30
+
31
+ EXPOSE 5000
32
+
33
+ CMD ["node", "dist/server.js"]
@@ -0,0 +1,32 @@
1
+ # Node modules
2
+ node_modules/
3
+ package-lock.json
4
+
5
+ # Build output
6
+ dist/
7
+ build/
8
+
9
+ # Env files
10
+ .env
11
+ .env.production
12
+
13
+ # Logs
14
+ logs/
15
+ *.log
16
+ npm-debug.log*
17
+ yarn-debug.log*
18
+ pnpm-debug.log*
19
+
20
+ # OS files
21
+ .DS_Store
22
+ Thumbs.db
23
+
24
+ # Coverage
25
+ coverage/
26
+
27
+ # IDE/editor
28
+ .vscode/
29
+ .idea/
30
+
31
+ # Docker
32
+ *.pid
@@ -0,0 +1,21 @@
1
+ services:
2
+ mongo:
3
+ image: mongo:8.2
4
+ container_name: server_database
5
+ restart: always
6
+
7
+ # only reachable from this machine (for local dev), not the internet
8
+ ports:
9
+ - "127.0.0.1:27017:27017"
10
+
11
+ volumes:
12
+ - mongo_data:/data/db
13
+
14
+ healthcheck:
15
+ test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping')"]
16
+ interval: 5s
17
+ timeout: 5s
18
+ retries: 5
19
+
20
+ volumes:
21
+ mongo_data:
@@ -0,0 +1,35 @@
1
+ import js from '@eslint/js';
2
+ import prettier from 'eslint-plugin-prettier';
3
+ import tseslint from 'typescript-eslint';
4
+
5
+ export default [
6
+ {
7
+ ignores: ['node_modules', 'dist', 'coverage'],
8
+ },
9
+
10
+ js.configs.recommended,
11
+
12
+ ...tseslint.configs.recommended,
13
+
14
+ {
15
+ files: ['**/*.ts'],
16
+ languageOptions: {
17
+ parser: tseslint.parser,
18
+ },
19
+ plugins: {
20
+ prettier,
21
+ },
22
+ rules: {
23
+ 'no-console': 'warn',
24
+ '@typescript-eslint/no-explicit-any': 'warn',
25
+ 'prettier/prettier': 'error',
26
+ '@typescript-eslint/no-unused-vars': [
27
+ 'error',
28
+ {
29
+ argsIgnorePattern: '^_',
30
+ varsIgnorePattern: '^_',
31
+ },
32
+ ],
33
+ },
34
+ },
35
+ ];