Skip to content

Instantly share code, notes, and snippets.

@mauroao
Last active April 26, 2025 12:17
Show Gist options
  • Save mauroao/6511c31170e34b8761d71a091ceebe7d to your computer and use it in GitHub Desktop.
Save mauroao/6511c31170e34b8761d71a091ceebe7d to your computer and use it in GitHub Desktop.

Revisions

  1. mauroao revised this gist May 22, 2020. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions readLineAssync.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,11 @@
    const readline = require('readline');

    const readLineAssync = () => {
    const readLineAsync = () => {
    const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
    input: process.stdin
    });

    return new Promise((resolve, reject) => {
    return new Promise((resolve) => {
    rl.prompt();
    rl.on('line', (line) => {
    rl.close();
    @@ -17,7 +16,7 @@ const readLineAssync = () => {

    const run = async () => {
    console.log('what is your name ? ');
    const line = await readLineAssync();
    const line = await readLineAsync();
    console.log(`Your name is ${line}`);
    };

  2. mauroao created this gist May 22, 2020.
    24 changes: 24 additions & 0 deletions readLineAssync.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    const readline = require('readline');

    const readLineAssync = () => {
    const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
    });

    return new Promise((resolve, reject) => {
    rl.prompt();
    rl.on('line', (line) => {
    rl.close();
    resolve(line);
    });
    });
    };

    const run = async () => {
    console.log('what is your name ? ');
    const line = await readLineAssync();
    console.log(`Your name is ${line}`);
    };

    run();