JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 94547
  • Score
    100M100P100Q165246F

Promise version of fs.readFile

Package Exports

  • fs-readfile-promise

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fs-readfile-promise) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fs-readfile-promise

Build Status Build status Coverage Status Dependency Status devDependency Status

Promises/A+ version of fs.readFile

var readFile = require('fs-readfile-promise');

readFile('path/to/file')
.then(function(buffer) {
  console.log(buffer.toString());
})
.catch(function(err) {
  console.log(err.message);
});

Based on the principle of modular programming, this module has only one functionality readFile, unlike other file system modules using promises. If you want to use a bunch of other fs methods in the promises' way, choose other modules such as q-io and fs-promise.

Installation

NPM version

Install with npm. (Make sure you have installed Node)

npm install --save fs-readfile-promise

API

var readFile = require('fs-readfile-promise');

readFile(filename [, options])

filename: String
options: Object or String (same as fs.readFile)
Return: Object (Promise)

When it finish reading the file, it will be fulfilled with an Buffer of the file as its first argument.

When it fails to read the file, it will be rejected with an error as its first argument.

var readFile = require('fs-readfile-promise');

var onFulfilled = function(buffer) {
  console.log(buffer.toString());
};

var onRejected = function(err) {
  console.log('Cannot read the file.');
};

readFile('path/to/file').then(onFulfilled, onRejected);

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.