import { watch } from 'node:fs/promises' import { Worker } from 'node:worker_threads' let worker = new Worker('./app.js') async function reloadOnChange (dir) { const watcher = watch(dir, { recursive: true }) for await (const change of watcher) { if (change.filename.endsWith('.js')) { worker.terminate() worker = new Worker('./app.js') } } } // All the folder to watch for ['./src', './lib', './test'].map(reloadOnChange)