Interactive question.
Small abstraction layer on top the question method of Node's readline module.
question
readline
import { createInterface } from "node:readline/promises";const exampleQuestion = question(createInterface({ input: process.stdin, output: process.stdout,}));exampleQuestion({ format: value => parseInt(value, 18), query: "How old are you?", validate: value => (value < 18 ? "You must be at least 18 years old." : ""),}).then(console.log).catch(console.error); Copy
import { createInterface } from "node:readline/promises";const exampleQuestion = question(createInterface({ input: process.stdin, output: process.stdout,}));exampleQuestion({ format: value => parseInt(value, 18), query: "How old are you?", validate: value => (value < 18 ? "You must be at least 18 years old." : ""),}).then(console.log).catch(console.error);
Object with a question function that returns a promise.
Curried function with questionObject set in context.
questionObject
Interactive question with questionObject set in context.
Result of the value after formatting.
Options object for the question.
Promise with the question's answer.
Interactive question.
Remarks
Small abstraction layer on top the
question
method of Node'sreadline
module.Example
See