Skip to content

Instantly share code, notes, and snippets.

@chauthai
Created November 27, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chauthai/cb6108b95c3b98bff175 to your computer and use it in GitHub Desktop.
Save chauthai/cb6108b95c3b98bff175 to your computer and use it in GitHub Desktop.
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