From b691af71c03e1717123f4bbd363657415fe96ec3 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Fri, 30 Dec 2022 17:13:09 +0100 Subject: [PATCH] add dependency-free node restart function as suggested by @KaKi87 https://github.com/RobinLinus/snapdrop/issues/515#issuecomment-1365403786 --- index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.js b/index.js index 28bcb1f..84955fb 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,25 @@ process.on('unhandledRejection', (reason, promise) => { console.log(reason) }) +process.on( + 'uncaughtException', + () => { + process.once( + 'exit', + () => spawn( + process.argv.shift(), + process.argv, + { + cwd: process.cwd(), + detached: true, + stdio: 'inherit' + } + ) + ); + process.exit(); + } +); + const express = require('express'); const RateLimit = require('express-rate-limit'); const http = require('http');