is ENOENT from fs.createReadStream uncatchable?

fs.createReadStream is asynchronous with the event emitter style and does not throw exceptions (which only make sense for synchronous code). Instead it will emit an error event.

const fs = require('fs')

const stream = fs.createReadStream('foo');
stream.on('error', function (error) {console.log("Caught", error);});
stream.on('ready', function () {stream.read();});

Leave a Comment