Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
node-readfiles
Advanced tools
A lightweight node.js module to recursively read files in a directory.
npm install node-readfiles
You can safely add readfiles
anywhere in your project.
var readfiles = require('node-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:
readfiles.FULL_PATH
, readfiles.RELATIVE
, or readfiles.FILENAME
, wether the callback's returns the full-path, relative-path or only the filenames of the traversed files. (default is readfiles.RELATIVE
)?
matches one character*
matches zero or more characters**
matches zero or more 'directories' in a path-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 readfiles
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 read all files with that match "t?t" in a directory and display the contents.
var readfiles = require('readfiles');
readfiles('/path/to/dir/', {
filter: '*.t?t'
}, 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 using ES6 Promises
The npm package node-readfiles receives a total of 1,183,838 weekly downloads. As such, node-readfiles popularity was classified as popular.
We found that node-readfiles 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.