Warning: SimpleXMLElement::asXML(E:\phpstudy_pro\zhutiblog\sitemaps\sitemap_54.xml.tmp): failed to open stream: Permission denied in E:\phpstudy_pro\zhutiblog\dd.php on line 1322
Interface.question method | Node.js readline/promises module | Bun - AI智能索引
温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/readline/promises/Interface/question
点击访问原文链接

Interface.question method | Node.js readline/promises module | Bun

Interface.question method | Node.js readline/promises module | BunBuildDocsReferenceGuidesBlogDiscord/node:readline/promises/Interface/questionMquestion

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:readline/promises/Interface/questionMquestion

method

readline.promises.Interface.question { console.log('The food question timed out'); }, { once: true }); const answer = await rl.question('What is your favorite food? ', { signal }); console.log(`Oh, so your favorite food is ${answer}`); ```" data-algolia-static="false" data-algolia-merged="false" data-type="Method">question(query: string): Promisestring>;

The rl.question() method displays the query by writing it to the output, waits for user input to be provided on input, then invokes the callback function passing the provided input as the first argument.

When called, rl.question() will resume the input stream if it has been paused.

If the Interface was created with output set to null or undefined the query is not written.

If the question is called after rl.close(), it returns a rejected promise.

Example usage:

const answer = await rl.question('What is your favorite food? ');
console.log(`Oh, so your favorite food is ${answer}`);

Using an AbortSignal to cancel a question.

const signal = AbortSignal.timeout(10_000);

signal.addEventListener('abort', () => {
console.log('The food question timed out');
}, { once: true });

const answer = await rl.question('What is your favorite food? ', { signal });
console.log(`Oh, so your favorite food is ${answer}`);
@param query

A statement or query to write to output, prepended to the prompt.

@returns

A promise that is fulfilled with the user's input in response to the query.

question(query: string,options: Abortable): Promisestring>;

The rl.question() method displays the query by writing it to the output, waits for user input to be provided on input, then invokes the callback function passing the provided input as the first argument.

When called, rl.question() will resume the input stream if it has been paused.

If the Interface was created with output set to null or undefined the query is not written.

If the question is called after rl.close(), it returns a rejected promise.

Example usage:

const answer = await rl.question('What is your favorite food? ');
console.log(`Oh, so your favorite food is ${answer}`);

Using an AbortSignal to cancel a question.

const signal = AbortSignal.timeout(10_000);

signal.addEventListener('abort', () => {
console.log('The food question timed out');
}, { once: true });

const answer = await rl.question('What is your favorite food? ', { signal });
console.log(`Oh, so your favorite food is ${answer}`);
@param query

A statement or query to write to output, prepended to the prompt.

@returns

A promise that is fulfilled with the user's input in response to the query.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Interface.question method | Node.js readline/promises module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for method node:readline/promises.Interface.question | Bun