Skip to content

Instantly share code, notes, and snippets.

@pokle
Created August 23, 2017 12:15
Show Gist options
  • Save pokle/a5996c62b5ba125a467ce049ccdff537 to your computer and use it in GitHub Desktop.
Save pokle/a5996c62b5ba125a467ce049ccdff537 to your computer and use it in GitHub Desktop.
nodejs neeson template with back pressure
// Try this with: seq 1 10 | node ndjson.js
// Don't forget to npm install ndjson
const ndjson = require('ndjson')
const parser = ndjson.parse();
const printer = ndjson.serialize();
printer.pipe(process.stdout);
process.stdin
.pipe(parser)
.on('data', function(obj) {
console.error('GOT', obj)
parser.pause();
setTimeout(() => {
printer.write({...obj, processed: true});
parser.resume();
}, 1000);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment