{"id":17049343,"url":"https://github.com/samccone/monocle","last_synced_at":"2025-04-12T15:22:35.546Z","repository":{"id":57302519,"uuid":"8279108","full_name":"samccone/monocle","owner":"samccone","description":"a tool for watching things","archived":false,"fork":false,"pushed_at":"2017-10-06T21:21:19.000Z","size":58,"stargazers_count":17,"open_issues_count":5,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-26T09:51:17.621Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samccone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-18T23:00:52.000Z","updated_at":"2021-06-21T12:29:50.000Z","dependencies_parsed_at":"2022-09-20T16:55:09.551Z","dependency_job_id":null,"html_url":"https://github.com/samccone/monocle","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samccone%2Fmonocle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samccone%2Fmonocle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samccone%2Fmonocle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samccone%2Fmonocle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samccone","download_url":"https://codeload.github.com/samccone/monocle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248305846,"owners_count":21081575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T09:54:26.508Z","updated_at":"2025-04-12T15:22:35.524Z","avatar_url":"https://github.com/samccone.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/samccone/monocle.png?branch=master)](https://travis-ci.org/samccone/monocle)\n\n# Monocle -- a tool for watching things\n\n[![logo](https://raw.github.com/samccone/monocle/master/logo.png)](https://raw.github.com/samccone/monocle/master/logo.png)\n\nHave you ever wanted to watch a folder and all of its files/nested folders for changes. well now you can!\n\n## Installation\n\n```\nnpm install monocle\n```\n\n## Usage\n\n### Watch a directory:\n\n```js\nvar monocle = require('monocle')()\nmonocle.watchDirectory({\n  root: \u003croot directory\u003e,\n  fileFilter: \u003coptional\u003e,\n  directoryFilter: \u003coptional\u003e,\n  listener: fn(fs.stat+ object), //triggered on file change / addition\n  complete: \u003cfn\u003e //file watching all set up\n});\n```\n\nThe listener will recive an object with the following\n\n```js\n  name: \u003cfilename\u003e,\n  path: \u003cfilepath-relative\u003e,\n  fullPath: \u003cfilepath-absolute\u003e,\n  parentDir: \u003cparentDir-relative\u003e,\n  fullParentDir: \u003cparentDir-absolute\u003e,\n  stat: \u003csee fs.stats\u003e\n```\n\n[fs.stats](http://nodejs.org/api/fs.html#fs_class_fs_stats)\n\nWhen a new file is added to the directoy it triggers a file change and thus will be passed to your specified listener.\n\nThe two filters are passed through to `readdirp`.  More documentation can be found [here](https://github.com/thlorenz/readdirp#filters)\n\n### Watch a list of files:\n\n```js\nMonocle.watchFiles({\n  files: [], //path of file(s)\n  listener: \u003cfn(fs.stat+ object)\u003e, //triggered on file / addition\n  complete: \u003cfn\u003e //file watching all set up\n});\n```\n\n### Just watch path\n\nJust 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`.\n\n```js\nMonocle.watchPaths({\n  path: [], //list of paths, or a string of path\n  fileFilter: \u003coptional\u003e, // `*.js` for example\n  listener: \u003cfn(fs.stat+ object)\u003e, //triggered on file / addition\n  complete: \u003cfn\u003e //file watching all set up\n});\n```\n\n### Force to use fs.watch\n\nYou can use the USE_FS_WATCH env variable set to true, to force this behavior regardless of platform.\n\n## Why not just use fs.watch ?\n\n  - file watching is really bad cross platforms in node\n  - you need to be smart when using fs.watch as compared to fs.watchFile\n  - Monocle takes care of this logic for you!\n  - windows systems use fs.watch\n  - osx and linux uses fs.watchFile\n\n## License\n\nBSD\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamccone%2Fmonocle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamccone%2Fmonocle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamccone%2Fmonocle/lists"}