Skip to content

Commit 3615320

Browse files
committed
Terminate server process from CLI if CLI terminates unexpectedly
1 parent f495b83 commit 3615320

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

srcbook/src/cli.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ function startServer(port, callback) {
3333
callback();
3434
}
3535
});
36+
37+
// Kill the server (child) process when the CLI (parent) process terminates from an exception
38+
process.on('uncaughtException', (error) => {
39+
console.error(error);
40+
server.kill();
41+
});
3642
}
3743

3844
export default function program() {

0 commit comments

Comments
 (0)