Promisified version of fs.readFile
const readFilePromise = require('fs-readfile-promise');
(async () => {
const buffer = await readPromise('path/to/a/file');
buffer.toString(); //=> '... file contents ...'
})();
Based on the principle of modular programming, this module has only one functionality readFile
, unlike other Promise-based file system modules. If you'd like to use a bunch of other fs
methods in the Promise way, choose other modules such as q-io and promise-fs.
npm install fs-readfile-promise
const readFilePromise = require('fs-readfile-promise');
path: string
Buffer
Uint8Array
URL
integer
options: Object
(fs.readFile options) or string
(encoding)
Return: Promise<Buffer|string>
(async () => {
await readFilePromise('src.txt'); //=> <Buffer 48 69 2e>
await readFilePromise('src.txt', 'utf8'); //=> 'Hi.'
await readFilePromise('src.txt', {encoding: 'base64'}); //=> 'SGku'
})();
- read-utf8-file — Promisified
fs.readFile
with automatic BOM stripping, encoding validation and stringification - read-multiple-files — Read multiple files Observable way
ISC License © 2017 - 2018 Shinnosuke Watanabe