@misterzik/espressojs 3.3.3 → 3.3.4

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.
package/index.js CHANGED
@@ -136,6 +136,8 @@ app.use(errorHandler);
136
136
  let server;
137
137
 
138
138
  const startServer = () => {
139
+ logger.info(`Attempting to start server on port ${Port}...`);
140
+
139
141
  server = app.listen(Port, () => {
140
142
  logger.info(`
141
143
  ╔═══════════════════════════════════════════════════════╗
@@ -150,6 +152,20 @@ const startServer = () => {
150
152
  ╚═══════════════════════════════════════════════════════╝
151
153
  `);
152
154
  });
155
+
156
+ server.on('error', (error) => {
157
+ if (error.code === 'EADDRINUSE') {
158
+ logger.error(`Port ${Port} is already in use`);
159
+ } else {
160
+ logger.error(`Server error: ${error.message}`);
161
+ logger.error(`Stack: ${error.stack}`);
162
+ }
163
+ process.exit(1);
164
+ });
165
+
166
+ server.on('listening', () => {
167
+ logger.info(`Server is now listening on port ${Port}`);
168
+ });
153
169
  };
154
170
 
155
171
  const gracefulShutdown = (signal) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@misterzik/espressojs",
3
- "version": "3.3.3",
3
+ "version": "3.3.4",
4
4
  "description": "EspressoJS Introducing Espresso.JS, your ultimate Express configuration starting point and boilerplate. With its simplicity and lack of opinionation, EspressoJS offers plug-and-play configurations built on top of Express.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,28 +26,32 @@ function showCommand() {
26
26
 
27
27
  function runCommand() {
28
28
  if (cfgB !== undefined) {
29
- const cmd_ct = vmdLogo;
30
- console.log(`${cmd_ct}`);
31
- console.log(
32
- `Espresso CLI
33
- --------------
34
- Warming Up Configs..
35
- Running ....
36
-
37
- Instance Config:
38
- Configuration: ${cfgB.instance}
39
- Endpoint: http://localhost:${cfgB.port}
40
- JSON:`,
41
- JSON.stringify(cfgB, null, 2),
42
- `\n\nTo stop process press CTRL+C\n`
43
- );
29
+ console.log('\n╔═══════════════════════════════════════════════════════╗');
30
+ console.log('║ ESPRESSO.JS CLI ║');
31
+ console.log('╚═══════════════════════════════════════════════════════╝\n');
32
+
33
+ console.log('🚀 Starting server...\n');
34
+ console.log(`📋 Configuration:`);
35
+ console.log(` Environment: ${cfgB.instance}`);
36
+ console.log(` Port: ${cfgB.port}`);
37
+ console.log(` URL: http://localhost:${cfgB.port}`);
38
+ console.log(` MongoDB: ${cfgB.mongoDB?.enabled ? '✓ Enabled' : '✗ Disabled'}`);
39
+ console.log(` API: ${cfgB.api?.enabled ? '✓ Enabled' : '✗ Disabled'}`);
40
+
41
+ const apiCount = Object.keys(cfgB).filter(key => key.match(/^api\d*$/)).length;
42
+ if (apiCount > 1) {
43
+ console.log(` API Endpoints: ${apiCount} configured`);
44
+ }
45
+
46
+ console.log('\n💡 Press CTRL+C to stop the server\n');
47
+ console.log('─'.repeat(55) + '\n');
44
48
 
45
49
  const child = spawn(
46
50
  "node",
47
51
  ["index.js"],
48
52
  {
49
53
  stdio: "inherit",
50
- shell: true,
54
+ shell: false,
51
55
  env: {
52
56
  ...process.env,
53
57
  NODE_ENV: cfgB.instance,
@@ -57,14 +61,29 @@ JSON:`,
57
61
  );
58
62
 
59
63
  child.on("error", (error) => {
60
- console.error(`Error: ${error.message}`);
64
+ console.error(`Error starting server: ${error.message}`);
65
+ process.exit(1);
61
66
  });
62
67
 
63
- child.on("exit", (code) => {
64
- if (code !== 0) {
65
- console.error(`Process exited with code ${code}`);
68
+ child.on("exit", (code, signal) => {
69
+ if (signal) {
70
+ console.log(`Server process killed with signal ${signal}`);
71
+ } else if (code !== 0) {
72
+ console.error(`Server process exited with code ${code}`);
73
+ } else {
74
+ console.log(`Server process exited cleanly`);
66
75
  }
67
- process.exit(code);
76
+ process.exit(code || 0);
77
+ });
78
+
79
+ // Keep the CLI process alive
80
+ process.on('SIGINT', () => {
81
+ console.log('\nShutting down server...');
82
+ child.kill('SIGINT');
83
+ });
84
+
85
+ process.on('SIGTERM', () => {
86
+ child.kill('SIGTERM');
68
87
  });
69
88
  }
70
89
  }