const express = require("express"); const { spawn } = require("child_process"); const path = require("path"); const app = express(); // Set bot/ as the working directory for all subprocess operations const botDirectory = path.join(__dirname, "bot"); // Start the bot in the background with bot/ as its root directory const botProcess = spawn("node", ["app.js"], { cwd: botDirectory, stdio: "inherit" }); app.get("/", (req, res) => { res.send("hello"); }); // Start the server const PORT = 7860; const server = app.listen(PORT, "0.0.0.0", () => { console.log(`Server running on http://0.0.0.0:${PORT}`); }); // Gracefully terminate the bot process on exit process.on("SIGINT", () => { console.log("Shutting down..."); botProcess.kill(); server.close(() => process.exit(0)); });