UNPKG

nhb-express

Version:
54 lines (44 loc) • 1.11 kB
import configs from '@/configs'; import { connectDB } from '@/configs/db'; import chalk from 'chalk'; import type { Server } from 'http'; import app from './app'; let server: Server; const bootStrap = async () => { try { // Connect to DB await connectDB(); // Listen to the Server server = app.listen(configs.port, () => { console.info( chalk.yellowBright(`šŸ‘‚ Server is Listening on Port: ${configs.port}`) ); }); } catch (error) { if (error instanceof Error) { console.error(chalk.red(`🚫 Error Occurred: ${error.message}`)); } else { console.error(chalk.red('šŸ›‘ Unknown Error Occurred!')); } } }; bootStrap().catch(console.dir); process.on('unhandledRejection', (err) => { console.error( chalk.redBright( `🚫 Unhandled Rejection Detected!\nšŸ›‘ Server is Shutting Down... ${err}` ) ); if (server) { server.close(() => { process.exit(1); }); } process.exit(1); }); process.on('uncaughtException', () => { console.error( chalk.redBright(`🚫 Uncaught Exception Detected!\nšŸ›‘ Server is Shutting Down...`) ); process.exit(1); });