read-input
Easily read from stdin or files.
read()
read(files, fn)
Reads from files. If no files are given, read from stdin.
The err
argument will always be null, as errors will be part of res
.
var read = require('read-input');
var fnames = process.argv.slice(2);
read(fnames, function (err, res) {
res.data
res.error
res.stdin
res.files
});
You can also iterate through res.files
.
read(fnames, function (err, res) {
res.files.forEach(function (f) {
f.data
f.error
f.stdin
f.name
}
});
If files
is a blank array (or null), data will be read from stdin. The
resulting data will have a similar schema.
read([], function (err, res) {
...
});
read.stdin()
read.stdin(fn)
Read data from standard input. The err
argument will always be null.
read.stdin(function (err, data) {
console.log(data);
});
res
The results value is an object passed to the callback of read()
.
data
(String) — a concatenation of all data in all the files.error
(Error) — The first error in all files. undefined
if successful.stdin
(Boolean) — is true
if the file is read from stdinfiles
(Array) — A list of files.
Each of the items in files
has a similar list of values:
data
(String) — File dataerror
(Error) — error, if applicablestdin
(Boolean) — is true
if the file is read from stdinname
(String) — File name
See read() for an example.
Thanks
read-input © 2014+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors.
ricostacruz.com ·
GitHub @rstacruz ·
Twitter @rstacruz