我有一个带有 package.json
的 Node 应用程序,如下所示:
{
"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
时,会记录此日志
Running version: 0.0.99
当我在 VS Code 中启动(按 F5)时,此日志
Running version: undefined
我需要对 launch.json
进行哪些更改才能在 VS Code 中启动应用,就像在命令提示符中输入 npm start
一样?
最佳答案
我现在可以使用以下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}"
}
]
}
关于node.js - 如何让 VSCode 运行像 "npm start"这样的 Node 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42146713/