diff --git a/package.json b/package.json index a21b128..a0eaf45 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,15 @@ "module": "index.ts", "type": "module", "private": true, + "scripts": { + "start": "bun run src/index.ts", + "build": "tsc", + "dev": "bun --watch src/index.ts", + "test": "bun test" + }, "devDependencies": { - "@types/bun": "latest" + "@types/bun": "latest", + "@types/node": "^20.11.19" }, "peerDependencies": { "typescript": "^5" @@ -13,6 +20,7 @@ "axios": "^1.8.4", "better-sqlite3": "^11.9.1", "dotenv": "^16.4.7", - "express": "^4.21.2" + "express": "^4.21.2", + "cross-env": "^7.0.3" } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 3e00386..063c027 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,14 +5,34 @@ import { startServer } from './server/server'; // Load environment variables dotenv.config(); -const PORT = 3000; +// Get port from environment or default to 3000 +const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3000; // Start the bot and server async function main() { - await startBot(); - startServer(PORT); + try { + console.log('Starting bot...'); + await startBot(); + console.log('Bot started successfully'); + + console.log('Starting server...'); + startServer(PORT); + console.log(`Server running on port ${PORT}`); + } catch (error) { + console.error('Error starting application:', error); + process.exit(1); + } } -main().catch((error) => { - console.error('Error starting the bot:', error); +// Handle process termination +process.on('SIGINT', () => { + console.log('Shutting down gracefully...'); + process.exit(0); }); + +process.on('SIGTERM', () => { + console.log('Shutting down gracefully...'); + process.exit(0); +}); + +main();