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

monocle

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monocle

a tool for watching directories for file changes

  • 1.1.50
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

Monocle -- a tool for watching things

logo

Have you ever wanted to watch a folder and all of its files/nested folders for changes. well now you can!

Installation

npm install monocle

Usage

Watch a directory:

var monocle = require('monocle')()
monocle.watchDirectory({
  root: <root directory>,
  fileFilter: <optional>,
  directoryFilter: <optional>,
  listener: fn(fs.stat+ object), //triggered on file change / addition
  complete: <fn> //file watching all set up
});

The listener will recive an object with the following

  name: <filename>,
  path: <filepath-relative>,
  fullPath: <filepath-absolute>,
  parentDir: <parentDir-relative>,
  fullParentDir: <parentDir-absolute>,
  stat: <see fs.stats>

fs.stats

When a new file is added to the directoy it triggers a file change and thus will be passed to your specified listener.

The two filters are passed through to readdirp. More documentation can be found here

Watch a list of files:

Monocle.watchFiles({
  files: [], //path of file(s)
  listener: <fn(fs.stat+ object)>, //triggered on file / addition
  complete: <fn> //file watching all set up
});

Just watch path

Just an alias of watchFiles and watchDirectory so you don't need to tell if that's a file or a directory by yourself. Parameter passed to path can be a string or a array of string.

Monocle.watchPaths({
  path: [], //list of paths, or a string of path
  fileFilter: <optional>, // `*.js` for example
  listener: <fn(fs.stat+ object)>, //triggered on file / addition
  complete: <fn> //file watching all set up
});

Why not just use fs.watch ?

  • file watching is really bad cross platforms in node
  • you need to be smart when using fs.watch as compared to fs.watchFile
  • Monocle takes care of this logic for you!
  • windows systems use fs.watch
  • osx and linux uses fs.watchFile

License

BSD

Keywords

FAQs

Package last updated on 20 Jun 2013

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