简体   繁体   English

在node.js中使用提示包

[英]Using the prompt package in node.js

I've recently learned the basics to using javascript through Node.js and have got a few questions as to how to use the prompt npm package to prompt the user for input. 我最近了解了通过Node.js使用javascript的基础知识,并且对如何使用提示npm包提示用户输入信息有一些疑问。 The url for the package is: https://npmjs.org/package/prompt 软件包的网址是: https : //npmjs.org/package/prompt

If someone could explain how to use the prompt package without complicating the details too much that would be helpful as in the browser it is as simple as typing: prompt('Your prompt here') . 如果有人可以解释如何使用提示包没有细节复杂的太多,这将是有帮助的在浏览器,它很简单,只要键入: prompt('Your prompt here')

Thanks 谢谢

There's a very simple example right in the documentation for the prompt package -- though I think the docs are actually out-of-date and that example didn't work for me. 提示包的文档中有一个非常简单的示例-尽管我认为这些文档实际上已经过时,并且该示例对我不起作用。

Here is an ultra-simple example. 这是一个非常简单的示例。 Note that you have to pass a callback to the prompt function, instead of receiving a return value from it, because that's just the way life is when you are using node.js ;) 请注意,您必须将回调传递给提示函数,而不是从其接收返回值,因为这就是使用node.js时的生活方式;)

var prompt = require("prompt");

prompt.start();

prompt.get("name", function(err, result) {
    console.log("Your name is ",result.name)
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM