+ refreshedVariable?: T,
+ listener: fs.WatchListener<string> = (event, filename) => {
+ if (Utils.isNotEmptyString(filename) && event === 'change') {
+ try {
+ logger.debug(`${logPrefix} ${fileType} file ${file} have changed, reload`);
+ refreshedVariable && (refreshedVariable = JSON.parse(fs.readFileSync(file, 'utf8')) as T);
+ } catch (error) {
+ FileUtils.handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
+ throwError: false,
+ });
+ }
+ }
+ }
+ ): fs.FSWatcher | undefined {
+ if (Utils.isNotEmptyString(file)) {
+ try {
+ return fs.watch(file, listener);
+ } catch (error) {
+ FileUtils.handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
+ throwError: false,
+ });
+ }
+ } else {
+ logger.info(`${logPrefix} No ${fileType} file to watch given. Not monitoring its changes`);
+ }
+ }
+
+ public static handleFileException(
+ file: string,
+ fileType: FileType,