Skip to content

Instantly share code, notes, and snippets.

@bbachi
Created January 24, 2021 04:48
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 bbachi/c6465b83a06c9cd630aac91783ed0733 to your computer and use it in GitHub Desktop.
Save bbachi/c6465b83a06c9cd630aac91783ed0733 to your computer and use it in GitHub Desktop.
NodeJS Stream
const { Writable } = require("stream");
const myWritableStream = (data) => {
return new Writable({
write(chunk, enc, next) {
data.push(chunk);
next();
}
})
}
const data = [];
const writable = myWritableStream(data);
writable.on('finish', () => {
console.log('Writing Done!!!', data.toString());
})
writable.write("This is the stream data 1\n");
writable.write("This is the stream data 2\n");
writable.write("This is the stream data 3\n");
writable.end("Done!!!!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment