A while ago I wrote a tiny timeout helper for async functions. In Node you don't need it:
import { setTimeout as sleep } from 'node:timers/promises'
await sleep(2000)
It also takes a value to resolve with and an AbortSignal, so a sleep can be cancelled:
const controller = new AbortController()
sleep(5000, 'done', { signal: controller.signal }).catch(() => {})
controller.abort()
In the browser you still need the new Promise((resolve) => setTimeout(resolve, ms)) version.