@engjts/nexus 0.1.8 → 0.1.9

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 (205) hide show
  1. package/package.json +1 -1
  2. package/BENCHMARK_REPORT.md +0 -343
  3. package/documentation/01-getting-started.md +0 -240
  4. package/documentation/02-context.md +0 -335
  5. package/documentation/03-routing.md +0 -397
  6. package/documentation/04-middleware.md +0 -483
  7. package/documentation/05-validation.md +0 -514
  8. package/documentation/06-error-handling.md +0 -465
  9. package/documentation/07-performance.md +0 -364
  10. package/documentation/08-adapters.md +0 -470
  11. package/documentation/09-api-reference.md +0 -548
  12. package/documentation/10-examples.md +0 -582
  13. package/documentation/11-deployment.md +0 -477
  14. package/documentation/12-sentry.md +0 -620
  15. package/documentation/13-sentry-data-storage.md +0 -996
  16. package/documentation/14-sentry-data-reference.md +0 -457
  17. package/documentation/15-sentry-summary.md +0 -409
  18. package/documentation/16-alerts-system.md +0 -745
  19. package/documentation/17-alert-adapters.md +0 -696
  20. package/documentation/18-alerts-implementation-summary.md +0 -385
  21. package/documentation/19-class-based-routing.md +0 -840
  22. package/documentation/20-websocket-realtime.md +0 -813
  23. package/documentation/21-cache-system.md +0 -510
  24. package/documentation/22-job-queue.md +0 -772
  25. package/documentation/23-sentry-plugin.md +0 -551
  26. package/documentation/24-testing-utilities.md +0 -1287
  27. package/documentation/25-api-versioning.md +0 -533
  28. package/documentation/26-context-store.md +0 -607
  29. package/documentation/27-dependency-injection.md +0 -329
  30. package/documentation/28-lifecycle-hooks.md +0 -521
  31. package/documentation/29-package-structure.md +0 -196
  32. package/documentation/30-plugin-system.md +0 -414
  33. package/documentation/31-jwt-authentication.md +0 -597
  34. package/documentation/32-cli.md +0 -268
  35. package/documentation/ALERTS-COMPLETE-SUMMARY.md +0 -429
  36. package/documentation/ALERTS-INDEX.md +0 -330
  37. package/documentation/ALERTS-QUICK-REFERENCE.md +0 -286
  38. package/documentation/README.md +0 -178
  39. package/documentation/index.html +0 -34
  40. package/modern_framework_paper.md +0 -1870
  41. package/public/css/style.css +0 -87
  42. package/public/index.html +0 -34
  43. package/public/js/app.js +0 -27
  44. package/src/advanced/cache/InMemoryCacheStore.ts +0 -68
  45. package/src/advanced/cache/MultiTierCache.ts +0 -194
  46. package/src/advanced/cache/RedisCacheStore.ts +0 -341
  47. package/src/advanced/cache/index.ts +0 -5
  48. package/src/advanced/cache/types.ts +0 -40
  49. package/src/advanced/graphql/SimpleDataLoader.ts +0 -42
  50. package/src/advanced/graphql/index.ts +0 -22
  51. package/src/advanced/graphql/server.ts +0 -252
  52. package/src/advanced/graphql/types.ts +0 -42
  53. package/src/advanced/jobs/InMemoryQueueStore.ts +0 -68
  54. package/src/advanced/jobs/JobQueue.ts +0 -556
  55. package/src/advanced/jobs/RedisQueueStore.ts +0 -367
  56. package/src/advanced/jobs/index.ts +0 -5
  57. package/src/advanced/jobs/types.ts +0 -70
  58. package/src/advanced/observability/APMManager.ts +0 -163
  59. package/src/advanced/observability/AlertManager.ts +0 -109
  60. package/src/advanced/observability/MetricRegistry.ts +0 -151
  61. package/src/advanced/observability/ObservabilityCenter.ts +0 -304
  62. package/src/advanced/observability/StructuredLogger.ts +0 -154
  63. package/src/advanced/observability/TracingManager.ts +0 -117
  64. package/src/advanced/observability/adapters.ts +0 -304
  65. package/src/advanced/observability/createObservabilityMiddleware.ts +0 -63
  66. package/src/advanced/observability/index.ts +0 -11
  67. package/src/advanced/observability/types.ts +0 -174
  68. package/src/advanced/playground/extractPathParams.ts +0 -6
  69. package/src/advanced/playground/generateFieldExample.ts +0 -31
  70. package/src/advanced/playground/generatePlaygroundHTML.ts +0 -1956
  71. package/src/advanced/playground/generateSummary.ts +0 -19
  72. package/src/advanced/playground/getTagFromPath.ts +0 -9
  73. package/src/advanced/playground/index.ts +0 -8
  74. package/src/advanced/playground/playground.ts +0 -250
  75. package/src/advanced/playground/types.ts +0 -49
  76. package/src/advanced/playground/zodToExample.ts +0 -16
  77. package/src/advanced/playground/zodToParams.ts +0 -15
  78. package/src/advanced/postman/buildAuth.ts +0 -31
  79. package/src/advanced/postman/buildBody.ts +0 -15
  80. package/src/advanced/postman/buildQueryParams.ts +0 -27
  81. package/src/advanced/postman/buildRequestItem.ts +0 -36
  82. package/src/advanced/postman/buildResponses.ts +0 -11
  83. package/src/advanced/postman/buildUrl.ts +0 -33
  84. package/src/advanced/postman/capitalize.ts +0 -4
  85. package/src/advanced/postman/generateCollection.ts +0 -59
  86. package/src/advanced/postman/generateEnvironment.ts +0 -34
  87. package/src/advanced/postman/generateExampleFromZod.ts +0 -21
  88. package/src/advanced/postman/generateFieldExample.ts +0 -45
  89. package/src/advanced/postman/generateName.ts +0 -20
  90. package/src/advanced/postman/generateUUID.ts +0 -11
  91. package/src/advanced/postman/getTagFromPath.ts +0 -10
  92. package/src/advanced/postman/index.ts +0 -28
  93. package/src/advanced/postman/postman.ts +0 -156
  94. package/src/advanced/postman/slugify.ts +0 -7
  95. package/src/advanced/postman/types.ts +0 -140
  96. package/src/advanced/realtime/index.ts +0 -18
  97. package/src/advanced/realtime/websocket.ts +0 -231
  98. package/src/advanced/sentry/index.ts +0 -1236
  99. package/src/advanced/sentry/types.ts +0 -355
  100. package/src/advanced/static/generateDirectoryListing.ts +0 -47
  101. package/src/advanced/static/generateETag.ts +0 -7
  102. package/src/advanced/static/getMimeType.ts +0 -9
  103. package/src/advanced/static/index.ts +0 -32
  104. package/src/advanced/static/isSafePath.ts +0 -13
  105. package/src/advanced/static/publicDir.ts +0 -21
  106. package/src/advanced/static/serveStatic.ts +0 -225
  107. package/src/advanced/static/spa.ts +0 -24
  108. package/src/advanced/static/types.ts +0 -159
  109. package/src/advanced/swagger/SwaggerGenerator.ts +0 -66
  110. package/src/advanced/swagger/buildOperation.ts +0 -61
  111. package/src/advanced/swagger/buildParameters.ts +0 -61
  112. package/src/advanced/swagger/buildRequestBody.ts +0 -21
  113. package/src/advanced/swagger/buildResponses.ts +0 -54
  114. package/src/advanced/swagger/capitalize.ts +0 -5
  115. package/src/advanced/swagger/convertPath.ts +0 -9
  116. package/src/advanced/swagger/createSwagger.ts +0 -12
  117. package/src/advanced/swagger/generateOperationId.ts +0 -21
  118. package/src/advanced/swagger/generateSpec.ts +0 -105
  119. package/src/advanced/swagger/generateSummary.ts +0 -24
  120. package/src/advanced/swagger/generateSwaggerUI.ts +0 -70
  121. package/src/advanced/swagger/generateThemeCss.ts +0 -53
  122. package/src/advanced/swagger/index.ts +0 -25
  123. package/src/advanced/swagger/swagger.ts +0 -237
  124. package/src/advanced/swagger/types.ts +0 -206
  125. package/src/advanced/swagger/zodFieldToOpenAPI.ts +0 -94
  126. package/src/advanced/swagger/zodSchemaToOpenAPI.ts +0 -50
  127. package/src/advanced/swagger/zodToOpenAPI.ts +0 -22
  128. package/src/advanced/testing/factory.ts +0 -509
  129. package/src/advanced/testing/harness.ts +0 -612
  130. package/src/advanced/testing/index.ts +0 -430
  131. package/src/advanced/testing/load-test.ts +0 -618
  132. package/src/advanced/testing/mock-server.ts +0 -498
  133. package/src/advanced/testing/mock.ts +0 -670
  134. package/src/cli/bin.ts +0 -9
  135. package/src/cli/cli.ts +0 -158
  136. package/src/cli/commands/add.ts +0 -178
  137. package/src/cli/commands/build.ts +0 -73
  138. package/src/cli/commands/create.ts +0 -166
  139. package/src/cli/commands/dev.ts +0 -85
  140. package/src/cli/commands/generate.ts +0 -99
  141. package/src/cli/commands/help.ts +0 -95
  142. package/src/cli/commands/init.ts +0 -91
  143. package/src/cli/commands/version.ts +0 -38
  144. package/src/cli/index.ts +0 -6
  145. package/src/cli/templates/generators.ts +0 -359
  146. package/src/cli/templates/index.ts +0 -680
  147. package/src/cli/utils/exec.ts +0 -52
  148. package/src/cli/utils/file-system.ts +0 -78
  149. package/src/cli/utils/logger.ts +0 -111
  150. package/src/core/adapter.ts +0 -88
  151. package/src/core/application.ts +0 -1453
  152. package/src/core/context-pool.ts +0 -79
  153. package/src/core/context.ts +0 -856
  154. package/src/core/index.ts +0 -94
  155. package/src/core/middleware.ts +0 -272
  156. package/src/core/performance/buffer-pool.ts +0 -108
  157. package/src/core/performance/middleware-optimizer.ts +0 -162
  158. package/src/core/plugin/PluginManager.ts +0 -435
  159. package/src/core/plugin/builder.ts +0 -358
  160. package/src/core/plugin/index.ts +0 -50
  161. package/src/core/plugin/types.ts +0 -214
  162. package/src/core/router/file-router.ts +0 -623
  163. package/src/core/router/index.ts +0 -260
  164. package/src/core/router/radix-tree.ts +0 -242
  165. package/src/core/serializer.ts +0 -397
  166. package/src/core/store/index.ts +0 -30
  167. package/src/core/store/registry.ts +0 -178
  168. package/src/core/store/request-store.ts +0 -240
  169. package/src/core/store/types.ts +0 -233
  170. package/src/core/types.ts +0 -616
  171. package/src/database/adapter.ts +0 -35
  172. package/src/database/adapters/index.ts +0 -1
  173. package/src/database/adapters/mysql.ts +0 -669
  174. package/src/database/database.ts +0 -70
  175. package/src/database/dialect.ts +0 -388
  176. package/src/database/index.ts +0 -12
  177. package/src/database/migrations.ts +0 -86
  178. package/src/database/optimizer.ts +0 -125
  179. package/src/database/query-builder.ts +0 -404
  180. package/src/database/realtime.ts +0 -53
  181. package/src/database/schema.ts +0 -71
  182. package/src/database/transactions.ts +0 -56
  183. package/src/database/types.ts +0 -87
  184. package/src/deployment/cluster.ts +0 -471
  185. package/src/deployment/config.ts +0 -454
  186. package/src/deployment/docker.ts +0 -599
  187. package/src/deployment/graceful-shutdown.ts +0 -373
  188. package/src/deployment/index.ts +0 -56
  189. package/src/index.ts +0 -281
  190. package/src/security/adapter.ts +0 -318
  191. package/src/security/auth/JWTPlugin.ts +0 -234
  192. package/src/security/auth/JWTProvider.ts +0 -316
  193. package/src/security/auth/adapter.ts +0 -12
  194. package/src/security/auth/jwt.ts +0 -234
  195. package/src/security/auth/middleware.ts +0 -188
  196. package/src/security/csrf.ts +0 -220
  197. package/src/security/headers.ts +0 -108
  198. package/src/security/index.ts +0 -60
  199. package/src/security/rate-limit/adapter.ts +0 -7
  200. package/src/security/rate-limit/memory.ts +0 -108
  201. package/src/security/rate-limit/middleware.ts +0 -181
  202. package/src/security/sanitization.ts +0 -75
  203. package/src/security/types.ts +0 -240
  204. package/src/security/utils.ts +0 -52
  205. package/tsconfig.json +0 -39
@@ -1,477 +0,0 @@
1
- # Deployment & Production Guide
2
-
3
- Nexus Framework menyediakan fitur-fitur production-ready untuk deployment:
4
-
5
- ## Table of Contents
6
-
7
- 1. [Graceful Shutdown](#graceful-shutdown)
8
- 2. [Clustering](#clustering)
9
- 3. [Environment Configuration](#environment-configuration)
10
- 4. [Docker Support](#docker-support)
11
-
12
- ---
13
-
14
- ## Graceful Shutdown
15
-
16
- Zero-downtime deployment dengan proper connection draining.
17
-
18
- ### Basic Usage
19
-
20
- ```typescript
21
- import { createApp } from 'nexus';
22
-
23
- const app = createApp();
24
-
25
- // Enable graceful shutdown
26
- app.gracefulShutdown({
27
- timeout: 30000, // Wait max 30 seconds for connections to drain
28
- verbose: true
29
- });
30
-
31
- // Add cleanup hooks
32
- app.onShutdown('database', async () => {
33
- await db.close();
34
- console.log('Database connection closed');
35
- }, 10); // Higher priority = runs first
36
-
37
- app.onShutdown('cache', async () => {
38
- await redis.disconnect();
39
- console.log('Redis connection closed');
40
- }, 5);
41
-
42
- app.listen(3000, () => {
43
- console.log('Server running on port 3000');
44
- });
45
- ```
46
-
47
- ### Configuration Options
48
-
49
- ```typescript
50
- app.gracefulShutdown({
51
- // Maximum time to wait for ongoing requests (ms)
52
- timeout: 30000,
53
-
54
- // Stop accepting new connections immediately
55
- stopAcceptingConnections: true,
56
-
57
- // Signals to listen for
58
- signals: ['SIGTERM', 'SIGINT'],
59
-
60
- // Custom health check during shutdown
61
- healthCheck: async () => ({
62
- status: 'healthy',
63
- details: { db: 'connected' }
64
- }),
65
-
66
- // Callbacks
67
- onShutdownStart: () => console.log('Shutdown starting...'),
68
- onShutdownComplete: () => console.log('Shutdown complete!'),
69
-
70
- // Enable verbose logging
71
- verbose: true
72
- });
73
- ```
74
-
75
- ### Programmatic Shutdown
76
-
77
- ```typescript
78
- // Trigger shutdown programmatically
79
- await app.shutdown();
80
-
81
- // Check if shutdown is in progress
82
- if (app.isShuttingDown()) {
83
- console.log('Server is shutting down...');
84
- }
85
- ```
86
-
87
- ---
88
-
89
- ## Clustering
90
-
91
- Multi-process deployment untuk high availability dan performance.
92
-
93
- ### Basic Usage
94
-
95
- ```typescript
96
- import { createApp, runClustered } from 'nexus';
97
-
98
- runClustered(() => {
99
- const app = createApp();
100
-
101
- app.get('/', (ctx) => ({
102
- message: 'Hello from worker!',
103
- workerId: process.pid
104
- }));
105
-
106
- app.listen(3000);
107
- }, {
108
- workers: 'auto', // Use all CPU cores
109
- verbose: true
110
- });
111
- ```
112
-
113
- ### Advanced Clustering
114
-
115
- ```typescript
116
- import { createApp, ClusterManager } from 'nexus';
117
-
118
- const app = createApp();
119
- const cluster = app.cluster({
120
- workers: 4,
121
- restartStrategy: 'rolling',
122
- restartDelay: 5000,
123
- maxRestarts: 10,
124
-
125
- onWorkerStart: (worker) => {
126
- console.log(`Worker ${worker.id} started`);
127
- },
128
-
129
- onWorkerExit: (worker, code, signal) => {
130
- console.log(`Worker ${worker.id} exited: ${code} ${signal}`);
131
- }
132
- });
133
-
134
- cluster.start(() => {
135
- app.get('/', (ctx) => ({ hello: 'world' }));
136
- app.listen(3000);
137
- });
138
- ```
139
-
140
- ### Cluster Management
141
-
142
- ```typescript
143
- // Check if primary process
144
- if (cluster.isPrimary()) {
145
- // Primary-only logic (e.g., scheduling)
146
-
147
- // Get cluster stats
148
- const stats = cluster.getStats();
149
- console.log(`Active workers: ${stats.activeWorkers}`);
150
-
151
- // Rolling restart all workers
152
- await cluster.rollingRestart();
153
-
154
- // Broadcast to all workers
155
- cluster.broadcast({ type: 'reload-config' });
156
- }
157
-
158
- // In worker process
159
- if (cluster.isWorker()) {
160
- process.on('message', (msg) => {
161
- if (msg.type === 'reload-config') {
162
- // Reload configuration
163
- }
164
- });
165
- }
166
- ```
167
-
168
- ---
169
-
170
- ## Environment Configuration
171
-
172
- Type-safe configuration dengan environment separation.
173
-
174
- ### Define Configuration
175
-
176
- ```typescript
177
- import { defineConfig } from 'nexus';
178
-
179
- const config = defineConfig({
180
- // Base configuration (all environments)
181
- base: {
182
- server: {
183
- port: 3000,
184
- host: 'localhost'
185
- },
186
- logging: {
187
- level: 'info'
188
- }
189
- },
190
-
191
- // Development overrides
192
- development: {
193
- logging: {
194
- level: 'debug',
195
- format: 'pretty'
196
- }
197
- },
198
-
199
- // Production overrides
200
- production: {
201
- server: {
202
- host: '0.0.0.0',
203
- port: process.env.PORT ? parseInt(process.env.PORT) : 3000
204
- },
205
- logging: {
206
- level: 'info',
207
- format: 'json'
208
- },
209
- security: {
210
- headers: 'strict'
211
- }
212
- },
213
-
214
- // Test overrides
215
- test: {
216
- database: {
217
- url: ':memory:'
218
- }
219
- }
220
- });
221
-
222
- // Use configuration
223
- const port = config.get('server.port');
224
- const dbUrl = config.get('database.url');
225
-
226
- if (config.isProduction()) {
227
- // Production-specific logic
228
- }
229
- ```
230
-
231
- ### Environment Variables
232
-
233
- ```bash
234
- # .env file
235
- APP_SERVER_PORT=8080
236
- APP_DATABASE_URL=postgres://localhost/mydb
237
- APP_LOGGING_LEVEL=debug
238
- ```
239
-
240
- ```typescript
241
- import { env, requireEnv } from 'nexus';
242
-
243
- // Get env with default
244
- const port = env('PORT', 3000);
245
-
246
- // Require env (throws if not set)
247
- const secret = requireEnv('JWT_SECRET');
248
- ```
249
-
250
- ### Configuration Files
251
-
252
- ```
253
- project/
254
- ├── .env # Base environment variables
255
- ├── .env.development # Development-specific
256
- ├── .env.production # Production-specific
257
- ├── .env.local # Local overrides (not committed)
258
- └── .env.example # Template for required vars
259
- ```
260
-
261
- ---
262
-
263
- ## Docker Support
264
-
265
- Generate optimized Docker configurations.
266
-
267
- ### Generate Docker Files
268
-
269
- ```typescript
270
- import { generateDockerFiles } from 'nexus';
271
-
272
- // Generate with default options
273
- generateDockerFiles();
274
-
275
- // Generate with custom options
276
- generateDockerFiles('.', {
277
- baseImage: 'node:20-alpine',
278
- port: 3000,
279
- healthCheck: true,
280
- healthEndpoint: '/__nexus/health',
281
- nonRootUser: true,
282
- multiStage: true
283
- });
284
- ```
285
-
286
- ### Generated Files
287
-
288
- ```
289
- project/
290
- ├── Dockerfile # Multi-stage optimized build
291
- ├── .dockerignore # Optimized ignore patterns
292
- ├── docker-compose.yml # Production compose file
293
- └── docker-compose.dev.yml # Development compose file
294
- ```
295
-
296
- ### Generated Dockerfile
297
-
298
- ```dockerfile
299
- # ============================================
300
- # Base Stage
301
- # ============================================
302
- FROM node:20-alpine AS base
303
- WORKDIR /app
304
-
305
- # ============================================
306
- # Dependencies Stage
307
- # ============================================
308
- FROM base AS deps
309
- COPY package*.json ./
310
- RUN npm ci --only=production
311
-
312
- # ============================================
313
- # Build Stage
314
- # ============================================
315
- FROM base AS build
316
- COPY package*.json ./
317
- RUN npm ci
318
- COPY . .
319
- RUN npm run build
320
-
321
- # ============================================
322
- # Production Stage
323
- # ============================================
324
- FROM base AS production
325
-
326
- # Create non-root user for security
327
- RUN addgroup --system --gid 1001 nodejs
328
- RUN adduser --system --uid 1001 nexus
329
-
330
- ENV NODE_ENV=production
331
-
332
- COPY --from=deps --chown=nexus:nodejs /app/node_modules ./node_modules
333
- COPY --from=build --chown=nexus:nodejs /app/dist ./dist
334
- COPY --from=build --chown=nexus:nodejs /app/package.json ./
335
-
336
- USER nexus
337
-
338
- EXPOSE 3000
339
-
340
- HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
341
- CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
342
-
343
- CMD ["node", "dist/index.js"]
344
- ```
345
-
346
- ### Docker Commands
347
-
348
- ```bash
349
- # Build image
350
- docker build -t myapp .
351
-
352
- # Run container
353
- docker run -p 3000:3000 myapp
354
-
355
- # Using docker-compose
356
- docker-compose up -d
357
-
358
- # Development with hot-reload
359
- docker-compose -f docker-compose.dev.yml up
360
- ```
361
-
362
- ### Custom Docker Configuration
363
-
364
- ```typescript
365
- import { createDocker } from 'nexus';
366
-
367
- const docker = createDocker({
368
- baseImage: 'node:20-alpine',
369
- port: 8080,
370
- entrypoint: 'dist/server.js',
371
- env: {
372
- TZ: 'UTC',
373
- NODE_OPTIONS: '--max-old-space-size=512'
374
- },
375
- labels: {
376
- 'app.version': '1.0.0',
377
- 'app.maintainer': 'team@example.com'
378
- }
379
- });
380
-
381
- // Generate individual files
382
- const dockerfile = docker.generateDockerfile();
383
- const dockerignore = docker.generateDockerignore();
384
- const compose = docker.generateComposeFile({
385
- services: {
386
- redis: {
387
- image: 'redis:alpine',
388
- ports: ['6379:6379']
389
- }
390
- }
391
- });
392
- ```
393
-
394
- ---
395
-
396
- ## Complete Production Setup
397
-
398
- ```typescript
399
- import {
400
- createApp,
401
- defineConfig,
402
- runClustered,
403
- generateDockerFiles
404
- } from 'nexus';
405
-
406
- // Configuration
407
- const config = defineConfig({
408
- base: {
409
- server: { port: 3000 }
410
- },
411
- production: {
412
- server: { port: parseInt(process.env.PORT || '3000') },
413
- security: { headers: 'strict' }
414
- }
415
- });
416
-
417
- // Generate Docker files (run once during setup)
418
- if (process.argv.includes('--docker')) {
419
- generateDockerFiles('.', { port: config.get('server.port') });
420
- process.exit(0);
421
- }
422
-
423
- // Run with clustering in production
424
- runClustered(() => {
425
- const app = createApp({ debug: config.isDevelopment() });
426
-
427
- // Enable graceful shutdown
428
- app.gracefulShutdown({
429
- timeout: 30000,
430
- verbose: config.isDevelopment()
431
- });
432
-
433
- // Add shutdown hooks
434
- app.onShutdown('database', async () => {
435
- await db.close();
436
- });
437
-
438
- // Enable observability
439
- app.observe({
440
- metrics: { enabled: true },
441
- health: {
442
- endpoint: '/__nexus/health',
443
- checks: [
444
- { name: 'database', check: async () => ({ status: 'up' }) }
445
- ]
446
- }
447
- });
448
-
449
- // Routes
450
- app.get('/', (ctx) => ({ status: 'ok' }));
451
-
452
- // Start server
453
- app.start({
454
- port: config.get('server.port'),
455
- host: '0.0.0.0'
456
- });
457
-
458
- console.log(`Worker ${process.pid} listening on port ${config.get('server.port')}`);
459
-
460
- }, {
461
- workers: config.isProduction() ? 'auto' : 1,
462
- verbose: config.isDevelopment()
463
- });
464
- ```
465
-
466
- ---
467
-
468
- ## Best Practices
469
-
470
- 1. **Always use graceful shutdown** in production
471
- 2. **Use clustering** to utilize all CPU cores
472
- 3. **Separate configuration** by environment
473
- 4. **Use multi-stage Docker builds** for smaller images
474
- 5. **Run as non-root user** in containers
475
- 6. **Include health checks** for orchestration platforms
476
- 7. **Set proper timeouts** for connection draining
477
- 8. **Add shutdown hooks** for cleanup (DB, Redis, etc.)