如何让VSCode运行像“npm start”这样的节点应用程序?

时间:2017-02-09 20:57:05

标签: node.js visual-studio-code

我有一个package.json的节点应用程序,如下所示:

{
    "name": "myexpressapp",   
    "version": "0.0.99",   
    "scripts": {
    "start": "node ./bin/www"   },  
    //etc
}

并在app.js我有

console.log ("Running version: "+process.env.npm_package_version);

当我在命令提示符下运行npm start时,会记录

  

正在运行的版本:0.0.99

当我在VS Code中开始(按 F5 )时记录

  

正在运行的版本:未定义

我需要对launch.json在VS Code中启动应用程序做出哪些更改,就像我在命令提示符下输入npm start一样?

1 个答案:

答案 0 :(得分:0)

我现在可以使用以下launch.json

来运行它(但不能调试)
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM#3",
            "runtimeExecutable": "npm",
            "windows": {
                "runtimeExecutable": "npm.cmd"
            },
            "runtimeArgs": [

                "start"
            ],
            "port": 5858,
            "cwd": "${workspaceRoot}"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program#1",
            "program": "app.js",
            "cwd": "${workspaceRoot}"
        }

    ]
}