Skip to content
Asynchronously reads an array of files and returns their contents
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.npmignore
LICENSE.mkd
README.mkd
package.json
read-files.js
test.js

README.mkd

read-files extends fs by the static method readFiles.

fs.readFiles(filenames[, encoding], callback)

Asynchronously reads the entire contents of the files specified in filenames.

filenames is an array of filenames.

encoding is a string specifying the files' encodings. The default is "utf8".

callback is a callback function that is passed two arguments (err, data) where data is an object of the form:

{
    filename1: file1contents,
    filename2: file2contents,
    …
}

Example:

var fs = require("fs");
    require("read-files");

fs.readFiles([ "file1", "file2" ], "utf8", function(err, data) {
    if (err) throw err;

    console.log(data);
});
Something went wrong with that request. Please try again.