Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

readdirp

Package Overview
Dependencies
Maintainers
2
Versions
43
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.

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50M
decreased by-14.55%
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 03 Oct 2024

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