Node.js console gets closed immediately after i execute the program from Visual Studio 2012 in Windows 8

前端 未结 7 1018
臣服心动
臣服心动 2021-01-01 23:20

I have installed Node.js in Windows 8 PC and installed the Node.js plugin for Visual Studio 2012. I executed a basic program from Visual St

7条回答
  •  滥情空心
    2021-01-02 00:08

    Instead of directly executing node app.js from Visual Studio, you could instead call a batch file:

    wait.bat app.js
    

    Which inside of wait.bat it simply:

    node %1
    pause press [enter]
    

    or, you could do this on one line, or wrap it in a module or a function:

    require('readline')
        .createInterface(process.stdin, process.stdout)
        .question("Press [Enter] to exit...", function(){
            process.exit();
    });
    

    It's using an currently marked as "unstable" module of Node to read line input from stdin. It ignores the input though and then closes the process using the exit function.

提交回复
热议问题