Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The node-dir package is a utility library for Node.js that provides methods to read directories recursively, read files within directories, and perform other directory and file system related operations. It is useful for applications that need to handle file system operations extensively.
Reading all files in a directory recursively
This feature allows you to list all files within a directory and its subdirectories. The function `dir.files` takes a directory path and a callback function that receives an array of file paths.
const dir = require('node-dir');
dir.files('/path/to/dir', function(err, files) {
if (err) throw err;
console.log(files);
});
Reading all subdirectories within a directory
This function lists all subdirectories within a specified directory. It is useful for applications that need to analyze or manipulate directory structures.
const dir = require('node-dir');
dir.subdirs('/path/to/dir', function(err, subDirs) {
if (err) throw err;
console.log(subDirs);
});
Reading content of files in a directory
This method reads the content of each file in a directory sequentially. It provides the file content to a callback function and proceeds to the next file when the `next` function is called.
const dir = require('node-dir');
dir.readFiles('/path/to/dir', function(err, content, next) {
if (err) throw err;
console.log(content);
next();
});
fs-extra is a package that builds on the native 'fs' module, providing additional methods and simplifying file system operations. It includes methods similar to node-dir but also offers file copying, moving, and more comprehensive error handling. It is generally more robust than node-dir.
glob is a package that allows pattern matching for filenames. It can be used to find files in a directory that match a given pattern, which is somewhat similar to listing files with node-dir but with more flexibility in file selection based on patterns.
recursive-readdir is a minimalistic package specifically focused on recursively reading directories. It is similar to the recursive file listing feature of node-dir but is lighter and has fewer features, focusing only on reading directories.
asynchronous recursive file and directory operations for Node.js
read all files in directory and its subdirectories and pass the file contents to a callback
var dir = require('node-dir');
dir.readFiles(__dirname,
function(err, content, next) {
if (err) throw err;
console.log(content);
next();
},
function(err, files){
if (err) throw err;
console.log('finished reading files:',files);
}
);
iterate all files in the directory and its subdirectories and pass their file-system paths to a callback
var dir = require('node-dir');
dir.filePaths(__dirname, function(err, files) {
if (err) throw err;
console.log(files);
});
iterate all subdirectories in the directory (recursive) and pass their file-system paths to a callback
var dir = require('node-dir');
dir.subdirs(__dirname, function(err, subdirs) {
if (err) throw err;
console.log(subdirs);
});
iterate all files and subdirs in the directory (recursive) and pass their file-system paths to a callback
var dir = require('node-dir');
// by default returns an object containing two array properties (files and dirs)
dir.paths(__dirname, function(err, paths) {
if (err) throw err;
console.log('files:\n',paths.files);
console.log('subdirs:\n', paths.dirs);
});
// combine both files and subdirs into a single array
dir.paths(__dirname, true, function(err, paths) {
if (err) throw err;
console.log('paths:\n',paths);
});
MIT licensed (SEE LICENSE.txt)
FAQs
asynchronous file and directory operations for Node.js
The npm package node-dir receives a total of 2,502,620 weekly downloads. As such, node-dir popularity was classified as popular.
We found that node-dir 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.