Socket
Socket
Sign inDemoInstall

readdirp

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readdirp

Recursive version of fs.readdir with streaming API.


Version published
Weekly downloads
43M
decreased by-0.92%
Maintainers
2
Weekly downloads
 
Created

What is readdirp?

The readdirp npm package is a Node.js module that allows for reading the contents of directories recursively with a stream API. It provides a flexible and powerful way to filter, map, and reduce directory contents in an efficient manner. This package is particularly useful for tasks that involve file system operations, such as building file trees, searching for files with specific patterns, or processing files in batches.

What are readdirp's main functionalities?

Streaming directory contents

This feature allows you to stream the contents of a directory, filtering for specific file types (in this case, JavaScript files). It's useful for processing files as they are found.

const readdirp = require('readdirp');

readdirp('.', { fileFilter: '*.js' })
  .on('data', (entry) => {
    console.log(entry.path);
  })
  .on('end', () => console.log('Done'));

Promise API for directory reading

This feature provides a Promise-based API for reading directories, allowing for asynchronous file processing with better error handling and integration with async/await syntax.

const readdirp = require('readdirp');

readdirp('.', { depth: 1, fileFilter: '*.js' })
  .then(files => {
    files.forEach(file => console.log(file.path));
  })
  .catch(error => console.error('Error:', error));

Custom filter and entry formatting

This feature demonstrates how to use custom filters for file selection and how to format the entries returned by readdirp. It's useful for more complex file selection criteria and custom output formatting.

const readdirp = require('readdirp');

const options = {
  fileFilter: (entry) => entry.basename.startsWith('test'),
  entryType: 'files',
  alwaysStat: true,
  depth: 2
};

readdirp('.', options)
  .on('data', (entry) => {
    console.log(`${entry.path} - ${entry.stats.size} bytes`);
  });

Other packages similar to readdirp

Keywords

FAQs

Package last updated on 13 Oct 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc