Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-watcher

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-watcher

"A simple recursive directory watcher."

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
56K
decreased by-0.98%
Maintainers
1
Weekly downloads
 
Created
Source

Simple Watcher

A simple recursive directory watcher.

But why?

I know there's plenty of them out there, but most don't seem to care about the recursive option of Node's fs.watch(), which significantly improves performance on the supported platforms, especially for large directories.

Features:

  • Dead simple and dead lightweight.
  • No dependencies.
  • Leverages the recursive options on OS X and Windows; uses a fallback for other platforms.
  • Does not care about Windows reporting multiple changes for one file (a simple workaround for this below).

Usage

Basic example:

const watch = require('simple-watcher')

watch('/path/to/directory', (filePath) => {
  console.log(`Changed: ${filePath}`)
})

WinAPI's ReadDirectoryChangesW double reporting fix:

const watch = require('simple-watcher')

let last = { filePath: null, timestamp: null }
let delta = 300 // Adjust if needed.

watch('/path/to/directory', (filePath) => {

  // Skip if the last change within the delta time was the same.
  let now = Date.now()
  if (filePath === last.filePath && now - last.timestamp < delta) {
    return
  }

  // Save the change.
  last.filePath = filePath
  last.timestamp = now

  console.log(`Changed: ${filePath}`)
})

Keywords

FAQs

Package last updated on 16 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc