Why does the Node.js scripts console close instantly in Windows 8?

妖精的绣舞 提交于 2020-01-11 05:45:07

问题


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:


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



来源:https://stackoverflow.com/questions/17731442/why-does-the-node-js-scripts-console-close-instantly-in-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!