Skip to content

Instantly share code, notes, and snippets.

@umidjons
Created August 13, 2016 13:04
Show Gist options
  • Save umidjons/b1702a3883b86a0c0cc8b4df2ae8abed to your computer and use it in GitHub Desktop.
Save umidjons/b1702a3883b86a0c0cc8b4df2ae8abed to your computer and use it in GitHub Desktop.
Get input from standard input stream example

Get input from stdin example

"use strict";

process.stdin.setEncoding('utf8');

process.stdin.on('readable', ()=> {
    let input = process.stdin.read();

    if (input !== null) {
        input = input.trim();
    }

    if (input == 'exit' || input == 'quit' || input == 'bye') {
        process.exit();
    }

    console.log('Input:', input);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment