Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The 'findit' npm package is a simple and efficient tool for recursively searching through directories to find files and directories. It emits events for each file and directory it encounters, making it easy to handle file system traversal in a Node.js application.
Finding Files
This feature allows you to search for files within a specified directory. The 'file' event is emitted for each file found, and you can handle it by logging the file path or performing other operations.
const findit = require('findit');
const finder = findit('/path/to/search');
finder.on('file', (file, stat) => {
console.log('File: ' + file);
});
Finding Directories
This feature allows you to search for directories within a specified directory. The 'directory' event is emitted for each directory found, and you can handle it by logging the directory path or performing other operations.
const findit = require('findit');
const finder = findit('/path/to/search');
finder.on('directory', (dir, stat, stop) => {
console.log('Directory: ' + dir);
});
Handling Errors
This feature allows you to handle errors that occur during the search process. The 'error' event is emitted when an error is encountered, and you can handle it by logging the error or performing other error-handling operations.
const findit = require('findit');
const finder = findit('/path/to/search');
finder.on('error', (err) => {
console.error('Error: ' + err);
});
Stopping the Search
This feature allows you to stop the search process based on certain conditions. The 'stop' function can be called within the 'directory' event handler to halt the search when a specific directory is encountered.
const findit = require('findit');
const finder = findit('/path/to/search');
finder.on('directory', (dir, stat, stop) => {
if (dir === '/path/to/stop') stop();
});
The 'glob' package allows for pattern matching and file searching using glob patterns. It is more flexible in terms of specifying patterns for file matching compared to 'findit', but it may be less efficient for large directory trees.
The 'readdirp' package provides a recursive version of 'fs.readdir'. It offers a more modern API with promises and streams, making it easier to integrate with async/await syntax. It is similar to 'findit' in terms of functionality but provides more modern features.
The 'walk' package is another alternative for recursively walking through directories. It provides a similar event-based API to 'findit' but includes additional features like filtering and limiting the depth of the search.
Recursively walk directory trees. Think /usr/bin/find
.
var finder = require('findit')(process.argv[2] || '.');
var path = require('path');
finder.on('directory', function (dir, stat, stop) {
var base = path.basename(dir);
if (base === '.git' || base === 'node_modules') stop()
else console.log(dir + '/')
});
finder.on('file', function (file, stat) {
console.log(file);
});
finder.on('link', function (link, stat) {
console.log(link);
});
var find = require('findit')
Return an event emitter finder
that performs a recursive walk starting at
basedir
.
If you set opts.followSymlinks
, symlinks will be followed. Otherwise, a
'link'
event will fire but symlinked directories will not be walked.
If basedir
is actually a non-directory regular file, findit emits a single
"file" event for it then emits "end".
You can optionally specify a custom
fs
implementation with opts.fs
. opts.fs
should implement:
opts.fs.readdir(dir, cb)
opts.fs.lstat(dir, cb)
opts.fs.readlink(dir, cb)
- optional if your stat objects from
opts.fs.lstat
never return true for stat.isSymbolicLink()
Stop the traversal. A "stop"
event will fire and then no more events will
fire.
For each file, directory, and symlink file
, this event fires.
For each file, this event fires.
For each directory, this event fires with the path dir
.
Your callback may call stop()
on the first tick to tell findit to stop walking
the current directory.
For each symlink, this event fires.
Every time a symlink is read when opts.followSymlinks
is on, this event fires.
When the recursive walk is complete unless finder.stop()
was called, this
event fires.
When finder.stop()
is called, this event fires.
Whenever there is an error, this event fires. You can choose to ignore errors or
stop the traversal using finder.stop()
.
You can always get the source of the error by checking err.path
.
With npm do:
npm install findit
MIT
FAQs
walk a directory tree recursively with events
The npm package findit receives a total of 92,930 weekly downloads. As such, findit popularity was classified as popular.
We found that findit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.