-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathserver.stop.js
More file actions
26 lines (22 loc) · 796 Bytes
/
server.stop.js
File metadata and controls
26 lines (22 loc) · 796 Bytes
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
import { io } from 'socket.io-client';
const PORT = process.env.PORT || 8080;
const SERVER_URL = `http://localhost:${PORT}`;
// Connect to the control socket and ask the server to stop.
const socket = io(SERVER_URL, {
reconnectionAttempts: 3,
timeout: 2000,
});
socket.on('connect', () => {
console.log('Connected to server control socket, sending npmStop...');
socket.emit('npmStop');
// Give the server a moment to shutdown gracefully, then exit this helper.
setTimeout(() => {
console.log('Stop signal sent, exiting stop script.');
process.exit(0);
}, 1000);
});
socket.on('connect_error', (err) => {
console.error('Failed to connect to server control socket:', err.message || err);
// Exit non-zero to indicate failure to stop via socket.
process.exit(1);
});