pedestrian
Version:
Recursive directory walker for node
70 lines (39 loc) • 2.15 kB
Markdown
[](https://travis-ci.org/tandrewnichols/pedestrian) [](https://npmjs.org/package/pedestrian) [](https://npmjs.org/package/pedestrian) [](https://codeclimate.com/github/tandrewnichols/pedestrian) [](https://codeclimate.com/github/tandrewnichols/pedestrian) [](https://david-dm.org/tandrewnichols/pedestrian)
# Pedestrian
A recursive file walker for node.js
## Installation
`npm install pedestrian --save`
## Usage
Synchronously or asynchronously walk a file tree and receive an array of files back.
### API
#### walk(directory[, patterns])
Walk a file tree asynchronously. This function returns a promise.
```js
const pedestrian = require('pedestrian');
pedestrian.walk('dir').then(files => {
}, err => {
});
```
Or to get only particular files, pass one or more glob patterns as the second argument.
```js
pedestrian.walk('dir', '**/*.js').then(files => {
});
// or
pedestrian.walk('dir', ['*.js', '*.coffee']).then(files => {
});
```
Negative globs are also supported.
```js
pedestrian.walk('dir', ['**/*.js', '!**/foo.js']).then(files => {
});
```
#### walkSync(directory[, patterns])
The api for `walkSync` is the same as for `walk`, but instead of returning a promise, it returns the array of files.
```javascript
let files = pedestrian.walkSync('lib');
```
## N.B.
Both the sync and async versions work with either absolute or relatives paths. Relative paths should be relative to the caller, rather than the current working directory. The files that `pedestrian` returns will always be absolute paths, however.
See [minimatch](https://github.com/isaacs/minimatch) for more on the kinds of patterns you can use.
## Contributing
Please see [the contribution guidelines](CONTRIBUTING.md).