Skip to content

Instantly share code, notes, and snippets.

@bhongy
Last active January 4, 2022 12:07
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 bhongy/81afc6eced35a0ebeed685a0b5024f7a to your computer and use it in GitHub Desktop.
Save bhongy/81afc6eced35a0ebeed685a0b5024f7a to your computer and use it in GitHub Desktop.
[nodejs] A simple example how to write to a file from stdin using stream.
// from: http://book.mixu.net/node/ch9.html
'use strict';
const fs = require('fs');
const file = fs.createWriteStream('./output.txt');
process.stdin.pipe(file);
// stdin is paused by default
process.stdin.resume();
// then type things into stdin
// to complete, as far as I know, hit ^D (Ctrl-D) when cursor is at the start of the line to send EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment