handle stop signal

This commit is contained in:
Sam Hadow 2025-03-09 19:20:46 +01:00
parent b7907c94ae
commit e5d559b75c

View File

@ -70,3 +70,15 @@ io.on('connection', async (socket) => {
const server = http.listen(port, () => {
console.log(`server is running on port ${server.address().port}`);
});
// handle stop signal
const shutdown = () => {
console.log('Stopping server.');
process.exit();
// server.close(() => {
// console.log('Stopped server.');
// });
};
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);