# Read File List
> Read the entire contents of each file in a file list.
## Usage
```javascript
var readFileList = require( '@stdlib/fs/read-file-list' );
```
#### readFileList( filepaths\[, options], clbk )
Asynchronously reads the entire contents of each file in a file list.
```javascript
readFileList( [ __filename ], onFiles );
function onFiles( error, files ) {
if ( error ) {
throw error;
}
console.dir( files );
// => [{...}]
}
```
Each file is represented by an `object` with the following fields:
- **file**: file path.
- **data**: file contents as either a [`Buffer`][node-buffer] or `string`.
The function accepts the same options as [`readFile()`][@stdlib/fs/read-file].
#### readFileList.sync( filepaths\[, options] )
Synchronously reads the entire contents of each file in a file list.
```javascript
var out = readFileList.sync( [ __filename ] );
if ( out instanceof Error ) {
throw out;
}
console.dir( out );
// => [{...}]
```
The function accepts the same options as [`readFile.sync()`][@stdlib/fs/read-file].
## Examples
```javascript
var readFileList = require( '@stdlib/fs/read-file-list' );
/* Sync */
var files = readFileList.sync( [ __filename ], 'utf8' );
// returns
console.log( files instanceof Error );
// => false
files = readFileList.sync( [ 'beepboop' ], {
'encoding': 'utf8'
});
// returns
console.log( files instanceof Error );
// => true
/* Async */
readFileList( [ __filename ], onFiles );
readFileList( [ 'beepboop' ], onFiles );
function onFiles( error, files ) {
if ( error ) {
if ( error.code === 'ENOENT' ) {
console.error( 'A file does not exist.' );
} else {
throw error;
}
} else {
console.dir( files );
}
}
```
* * *
## CLI
### Usage
```text
Usage: read-file-list [options] ...
Options:
-h, --help Print this message.
-V, --version Print the package version.
--enc, --encoding encoding Encoding.
--flag flag Flag. Default: 'r'.
```
### Notes
- Relative file paths are resolved relative to the current working directory.
- Errors are written to `stderr`.
- File contents are written to `stdout` as newline-delimited JSON ([NDJSON][ndjson]).
### Examples
```bash
$ read-file-list ./README.md ./package.json
{"file":"...","data":"..."}
{"file":"...","data":"..."}
```
[@stdlib/fs/read-file]: https://www.npmjs.com/package/@stdlib/fs/tree/main/read-file
[node-buffer]: https://nodejs.org/api/buffer.html
[ndjson]: http://ndjson.org/