Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Watchr provides a normalised API the file watching APIs of different node versions, nested/recursive file and directory watching, and accurate detailed events for file/directory creations, updates, and deletions.
You install it via npm install watchr
and use it via require('watchr').watch(config)
. Available configuration options are:
path
a single path to watchpaths
an array of paths to watchlistener
a single change listener to fire when a change occurslisteners
an array of listeners to fire when a change occurs, overloaded to also accept
changeListener
a single change listener[changeListener]
an array of change listeners{eventName:eventListener}
an object keyed with the event names and valued with a single event listener{eventName:[eventListener]}
an object keyed with the event names and valued with an array of event listenersnext
(optional, defaults to null
) a completion callback to fire once the watchers have been setup, arguments are:
path
configuration option: err, watcherInstance
paths
configuration option: err, [watcherInstance,...]
stat
(optional, defaults to null
) a file stat object to use for the path, instead of fetching a new oneignoreHiddenFiles
(optional, defaults to false
) whether or not to ignored files which filename starts with a .
ignoreCommonPatterns
(optional, defaults to true
) whether or not to ignore common undesirable file patterns (e.g. .svn
, .git
, .DS_Store
, thumbs.db
, etc)ignoreCustomPatterns
(optional, defaults to null
) any custom ignore patterns that you would also like to ignore along with the common patternsinterval
(optional, defaults to 100
) for systems that poll to detect file changes, how often should it poll in millsecondspersistent
(optional, defaults to true
) whether or not we should keep the node process alive for as long as files are still being watchedThe following events are available to your via the listeners:
log
for debugging, receives the arguments logLevel ,args...
error
for gracefully listening to error events, receives the arguments err
watching
for when watching of the path has completed, receives the arguments err, isWatching
change
for listening to change events, receives the arguments changeType, fullPath, currentStat, previousStat
, received arguments will be:
'update', fullPath, currentStat, previousStat
'create', fullPath, currentStat, null
'delete', fullPath, null, previousStat
To wrap it all together, it would look like this:
// Require
watchr = require('watchr')
// Watch a directory or file
watchr.watch({
paths: ['path1','path2','path3'],
listeners: {
log: function(logLevel){
console.log('a log message occured:', arguments);
},
error: function(err){
console.log('an error occured:', err);
},
watching: function(err,watcherInstance,isWatching){
console.log('a new watcher instance finished setting up', arguments);
},
change: function(changeType,filePath,fileCurrentStat,filePreviousStat){
console.log('a change event occured:',arguments);
}
},
next: function(err,watchers){
console.log('watching for all our paths has completed', arguments);
}
});
You can test the above code snippet by installing watchr globally by running npm install -g watchr
to install watchr, then watchr <pathToWatch>
to watchr a particular path, and performing some file system modifications on that path.
Support can be found in the GitHub Issue Tracker
You can discover the history inside the History.md file
Licensed under the incredibly permissive MIT License
Copyright © 2012 Bevry Pty Ltd
Copyright © 2011 Benjamin Lupton
v2.3.0 2012 December 17
log
for debugging, receives the arguments logLevel ,args...
- watching
for when watching of the path has completed, receives the arguments err, isWatching
- change
for listening to change events, receives the arguments changeType, fullPath, currentStat, previousStat
- error
for gracefully listening to error events, receives the arguments err
- read the README to learn how to bind to these new eventschangeType
argument for change listeners has been changed for better clarity and consitency: - change
is now update
- new
is now create
- unlink
is now delete
require('watchr').watch
for better consitency: - if you send the paths
option, you will receive the arguments err, results
where results
is an array of watcher instances - if you send the path
option, you receive the arguments err, watcherInstance
FAQs
Better file system watching for Node.js
The npm package watchr receives a total of 20,896 weekly downloads. As such, watchr popularity was classified as popular.
We found that watchr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.