Open
Milestone started on Nov 18, 2025

Node watch better performance in windows or extenal drive

Node watching, in windows, can be slow.

We probably can act a solution like:

// system/watch.js




import { spawn } from 'node:child_process'
import { watch } from 'node:fs'
import { resolve } from 'node:path'

const ENGINE = resolve('./system-core/engine.js')

const WATCH_PATHS = [
  './server-public',
  './system-pkgs/htmlexpress/resources',
]

// Very small ignore list, keep it strict




const IGNORE_RE = /(^|[\\/])(\.git|node_modules|system-core)([\\/]|$)|(\.hmac$)|(\.keys$)/i

let child = null
let restarting = false
let timer = null

function start(args) {
  child = spawn(process.execPath, [ENGINE, ...args], { stdio: 'inherit' })
  child.on('exit', () => { child = null })
}

function stop() {
  if (!child) return
  // Try graceful first
  child.kill('SIGTERM')
  // Force kill after 800ms
  setTimeout(() => {
    if (child) child.kill('SIGKILL')
  }, 800)
}

function restart(args, reasonPath) {
  if (restarting) return
  restarting = true

  // optional: log
  // console.log('[watch] restart →', reasonPath)

  stop()
  // Give OS a breath (Windows)
  setTimeout(() => {
    start(args)
    restarting = false
  }, 150)
}

function main() {
  const args = process.argv.slice(2) // pass-through: "start", etc.
  start(args)

  for (const p of WATCH_PATHS) {
    const abs = resolve(p)

    // recursive works only on Windows/macOS. On Linux it throws.
    const recursive = process.platform !== 'linux'

    watch(abs, { recursive }, (eventType, filename) => {
      const full = filename ? `${abs}/${filename}` : abs
      if (IGNORE_RE.test(full)) return

      clearTimeout(timer)
      timer = setTimeout(() => restart(args, full), 120) // your debounce
    })
  }
}

main()
  • Work items 0
  • Merge requests 0
  • Participants 0
  • Labels 0
Loading
Loading
Loading
Loading
0% complete
0%
Start date
Nov 18, 2025
From
Nov 18 2025
Due date
No due date (275 days elapsed)
0
Work items 0
Open: 0 Closed: 0
0
Merge requests 0
Open: 0 Closed: 0 Merged: 0
0
Releases
None
Reference: staxis-platform%"Node watch better performance in windows or extenal drive"