Node.js 中是否有用于从命令行获取用户输入的模块?

发布于 2024-12-28 12:48:30 字数 439 浏览 3 评论 0原文

首先:我的意思不是解析 process.argv 数组中的参数和选项,而是提示用户并处理输入/输出。我浏览了 Node.js 官方模块列表,但没有找到任何以下部分或小节提到输入。事实上,在该页面上搜索“输入”只会得到 1 个与 YAML 有关的结果。

不管怎样,我认为 cli 输入应该是异步的,并且在使用 stdin.on('data') 之前我已经解决了这个问题,至少可以说这是很混乱的。对于节点模块来说,这似乎是一个完美的任务,它可能附带额外的好处,例如进度条、旋转器、彩色输出、输入验证等。

可能有一些模块可以做到这一点,但我找不到其中任何一个。

帮助!!

(澄清一下,我需要的唯一功能是简化处理用户输入)

First of all: I don't mean parsing arguments and options from the process.argv array, but prompting the user and handling input/output. I've looked through the Node.js official module list without finding any sections or subsections that mentions input. In fact a search for 'input' on that page only gets 1 result which has something to do with YAML.

Anyway, I suppose cli input should be asynchronous and I've solved this issue before using stdin.on('data') which was messy to say the least. This seems like a perfect task for a node module which could come with extra goodies such as progress bars, spinners, coloured output, input validation etc.

There probably are some modules out there that does this, but I can't find any of them.

Help!!

(To clarify, the only functionality I require is the simplification of handling user input)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬 2025-01-04 12:48:30

在这里搜索模块:http://eirikb.github.com/nipster/

另外,如果你想编写自己的:http://nodejs.org/docs/latest/api/all.html#readline< /a>

#node.js IRC 欢迎您:http://webchat.freenode.net/?channels=node.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文