You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

read-directory

Package Overview
Dependencies
5
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-directory

Read a directory of files


Version published
Weekly downloads
864
decreased by-61.87%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

read-directory

Read a directory of files.

Install

npm install --save read-directory

Examples

Async example:

var read = require('read-directory')
read('./files', function (err, contents) {
  console.log(contents)
})

Sync example:

var read = require('read-directory')
var contents = read.sync('./files')

Using in the browser with browserify & budo

Use the included browserify transform module to convert calls to read.sync to the contents of the directory.

Note that to use the browserify transform you must use read.sync, and the path to the file directory can not be a variable.

File that will be browserified & transformed:

var path = require('path')
var read = require('read-directory')
var contents = read.sync(path.join(__dirname, 'files'))

Browserify example:

browserify index.js -t read-directory -o bundle.js

budo example:

budo index.js:bundle.js -- -t read-directory

API

readDirectory

Read the contents of a directory asynchronously

Parameters

  • dir String – The directory to read
  • options Object
    • options.fs Object – alternate fs implementation, optional
    • options.dirnames Boolean – include or exclude subdirectory names in keys of returned object
    • options.encoding String – encoding of files, default: utf8
    • options.filter String – glob pattern for filtering files, examples: *.md, *.css
    • options.ignore String – glob pattern for ignoring files
    • options.ignore Array – array of glob patterns for ignoring files
    • options.transform Function – A function you can use to transform the contents of files after they are read

Examples

var read = require('read-directory')
read('./files', function (err, contents) {
  console.log(contents)
})

readDirectory.sync

Read the contents of a directory asynchronously

Parameters

  • dir String – The directory to read
  • options Object
    • options.fs Object – alternate fs implementation, optional
    • options.dirnames Boolean – include or exclude subdirectory names in keys of returned object
    • options.encoding String – encoding of files, default: utf8
    • options.filter String – glob pattern for filtering files, examples: *.md, *.css
    • options.ignore String – glob pattern for ignoring files
    • options.ignore Array – array of glob patterns for ignoring files
    • options.transform Function – A function you can use to transform the contents of files after they are read

Examples

var read = require('read-directory')
var contents = read.sync('./files')

License

MIT

FAQs

Package last updated on 14 Jul 2019

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc