Why does the Node.js scripts console close instant

2019-02-18 11:04发布

I've tried nearly every example for scripts I can find. Every sample opens the terminal for a split second. Even this closes as soon as input is entered. Is this normal?

    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条回答
放我归山
2楼-- · 2019-02-18 11:12

There are 2 options that control this in Tools/Options/Node.js Tools/General:

Wait for input when process exists abnormally Wait for input when process exists normally

Taken from https://nodejstools.codeplex.com/discussions/565665

查看更多
登录 后发表回答