-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstart.js
More file actions
58 lines (47 loc) · 1.33 KB
/
start.js
File metadata and controls
58 lines (47 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
const { spawn } = require("child_process");
const path = require("path");
console.log("🎮 Starting Secret Game MERN Stack...\n");
// Check if we're in development or production
const isDev = process.env.NODE_ENV !== "production";
if (isDev) {
console.log("🔧 Development Mode");
console.log("📦 Starting both backend and frontend...\n");
// Start backend
const backend = spawn("npm", ["run", "server"], {
stdio: "inherit",
shell: true,
cwd: __dirname,
});
// Start frontend after a short delay
setTimeout(() => {
const frontend = spawn("npm", ["run", "client"], {
stdio: "inherit",
shell: true,
cwd: __dirname,
});
frontend.on("error", (err) => {
console.error("❌ Frontend error:", err);
});
}, 2000);
backend.on("error", (err) => {
console.error("❌ Backend error:", err);
});
// Handle graceful shutdown
process.on("SIGINT", () => {
console.log("\n🛑 Shutting down gracefully...");
backend.kill();
process.exit(0);
});
} else {
console.log("🚀 Production Mode");
console.log("📦 Starting backend server...\n");
const server = spawn("node", ["backend/server.js"], {
stdio: "inherit",
shell: true,
cwd: __dirname,
});
server.on("error", (err) => {
console.error("❌ Server error:", err);
});
}