readFile
doesn't return a promise. The NodeJS by and large predates widespread use of promises and mostly uses simple callbacks instead.
To read the file, you pass in a simple callback, as this example from the documentation shows:
fs.readFile('/etc/passwd', function (err, data) {
if (err) throw err;
console.log(data);
});
There is a promisify-node
module available that wraps standard NodeJS modules in a promise-enabled API. Example from its docs:
var promisify = require("promisify-node");
var fs = promisify("fs")
fs.readFile("/etc/passwd").then(function(contents) {
console.log(contents);
});
I should emphasize that I don't know it and haven't used it, so I can't speak to how well it does its job. It appears to use nodegit-promise
, a "Bare bones Promises/A+ implementation with synchronous inspection" rather than JavaScript's Promise
(which is only fair; it predates JavaScript's Promise
by a couple of years).