node-input.js

An input library

Usage no npm install needed!

<script type="module">
  import nodeInputJs from 'https://cdn.skypack.dev/node-input.js';
</script>

README

VersionDownloads

Installation

npm: npm i node-input.js

About

node-input.js is a package for reading inputs from terminal/command line

Examples

Example with Async/Await

const { input } = require("node-input.js");

(async function main () {
    let name = await input("What is your name? ");
    let sport = await input("What is your favorite sport? ");

    console.log(`Hello ${name}, do want to play ${sport} together sometime?`);

    process.exit();
})();

Example with a stream

const { stream } = require("node-input.js");

let input = stream.connect((buffer) => {
    let args = buffer.toString().trim().split(" ");

    switch (args[0].toLowerCase()) {
        case "exit":
            process.exit();
            break;
        case "eval":
            let res = eval(args.slice(1).join(" "));
            console.log(res);
            break;
        case "disconnect":
            stream.disconnect(input);
            break;
    }
})

Working on

  • Synchronous input
  • Fixing input in REPL