Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A node polyfill for process.stderr in a browser
var WritableStream = require('stream');
var inherits = require('util').inherits;
module.exports = BrowserStderr;
inherits(BrowserStderr, WritableStream);
function BrowserStderr(opts) {
if (!(this instanceof BrowserStderr)) return new BrowserStderr(opts);
opts = opts || {};
WritableStream.call(this, opts);
this.label = (opts.label !== undefined) ? opts.label : 'stderr';
}
BrowserStderr.prototype.write = function(chunks, encoding, cb) {
var output = chunks.toString ? chunks.toString() : chunks;
if (this.label === false) {
console.log(output);
} else {
console.log(this.label+':', output);
}
process.nextTick(cb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.