为什么Node.js脚本控制台在Windows 8中立即关闭?

时间:2013-07-18 18:40:37

标签: node.js windows-8 console-application

我已经尝试了几乎所有可以找到的脚本的例子。每个样本都会打开终端一瞬间。输入输入后,即使这样也会关闭。这是正常的吗?

    var rl = require('readline');

var prompts = rl.createInterface(process.stdin, process.stdout);

prompts.question("How many servings of fruits and vegetables do you eat each day? ", function  (servings) {
    var message = '';

    if (servings < 5) {
        message = "Since you're only eating " + servings + 
        " right now, you might want to start eating " + (5 - servings) + " more.";
    } else {
        message = "Excellent, your diet is on the right track!";
    }

    console.log(message);

  process.exit();
});

1 个答案:

答案 0 :(得分:0)

在Tools / Options / Node.js工具/常规中有两个选项可以控制它:

当进程异常存在时等待输入 当进程正常存在时等待输入

取自https://nodejstools.codeplex.com/discussions/565665