简体   繁体   English

如何更改NodeJS CLI提示符

[英]How to change nodeJS CLI prompt

I want to change the prompt for the nodejs cli prompt. 我想将提示更改为nodejs cli提示。 I looked around but didn't find an solution. 我环顾四周,但没有找到解决方案。

Some people talked about a prompt module. 有人谈论了prompt模块。 But var p = require('prompt'); 但是var p = require('prompt'); just gives me an error 只是给我一个错误

You need to add the dependency to your project. 您需要将依赖项添加到您的项目中。

[sudo] npm install prompt [--save]

--save will add it to your package.json --save将其添加到您的package.json

My guess is that you are not using the p.start(); 我的猜测是您没有使用p.start();。 command. 命令。 So try out this simple example 所以尝试这个简单的例子

  var prompt = require('prompt');


  prompt.start();

  // 
  // Get two properties from the user: username and email 
  // 
  prompt.get(['username', 'email'], function (err, result) {
    // 
    // Log the results. 
    // 
    console.log('Command-line input received:');
    console.log('  username: ' + result.username);
    console.log('  email: ' + result.email);
  });

Also if you are new to npm and node in general, start your projects with 另外,如果您一般不熟悉npm和node,请使用

npm init

that creates your package.json file in which you provide your project's dependencies 创建您的package.json文件,您在其中提供项目的依赖项

the following command installs prompt for node and saves it in your package.json 以下命令将安装节点提示,并将其保存在package.json中

npm install -S prompt

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

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