Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
node-readdir
Advanced tools
A lightweight node.js module to recursively read files in a directory.
npm install readfiles
Asynchronusly read the files in a directory
A relative or absolute path of the directory to read files.
An optional object parameter with the following properties:
readdir.FULL_PATH
, readdir.RELATIVE
, or readdir.FILENAME
, wether the callback's returns the full-path, relative-path or only the filenames of the traversed files. (default is readdir.RELATIVE
)-1
is infinte, and 0
is none (defaults to -1).
(defaults to true)The callback function that is triggered everytime a file is read. If there's an error while reading the file the err
parameter will contain the error that occured, otherwise the if readContents
is true, the contents
parameter will be populated with the contents of the file encoded using the encoding
option.
[1] The contents
parameter will be null
when the readContents
option is false
.
The callback function that is triggered once all the files have been read, passing the number of files read and an array with the full path of all files.
The default behavior, is to recursively list all files in a directory. By default readdir
will exclude all dot files.
var readfiles = require('readfiles');
readfiles('/path/to/dir/', function (err, filename, contents) {
if (err) throw err;
console.log('File ' + filename + ':');
console.log(content);
}, function (err, count, files) {
console.log('Read ' + count + ' file(s)');
console.log(files.join('\n'));
});
Read all files in a directory, excluding sub-directories.
var readfiles = require('readfiles');
readfiles('/path/to/dir/', {
depth: 0
}, function (err, content, filename) {
if (err) throw err;
console.log('File ' + filename + ':');
console.log(content);
}, function (err, count, files) {
console.log('Read ' + count + ' file(s)');
console.log(files.join('\n'));
});
The above can also be accomplished using filter
.
var readfiles = require('readfiles');
readfiles('/path/to/dir/', {
filter: '*' // instead of the default '**'
}, function (err, content, filename) {
if (err) throw err;
console.log('File ' + filename + ':');
console.log(content);
}, function (err, count, files) {
console.log('Read ' + count + ' file(s)');
console.log(files.join('\n'));
});
Recursively read all files with "txt" extension in a directory and display the contents.
var readfiles = require('readfiles');
readfiles('/path/to/dir/', {
filter: '*.txt'
}, function (err, content, filename) {
if (err) throw err;
console.log('File ' + filename + ':');
console.log(content);
}, function (err, count, files) {
console.log('Read ' + count + ' text file(s)');
});
Recursively list all json files in a directory including all sub-directories, without reading the files.
var readfiles = require('readfiles');
readfiles('/path/to/dir/', {
filter: '*.json',
readContents: false
}, function (err, content, filename) {
if (err) throw err;
console.log('File ' + filename);
});
MIT licensed (See LICENSE.txt)
FAQs
A lightweight Node.js module to recursively read files in a directory
The npm package node-readdir receives a total of 8 weekly downloads. As such, node-readdir popularity was classified as not popular.
We found that node-readdir 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.