Last active
January 4, 2022 12:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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