[英]How can I make VSCode run a node app like “npm start”?
I have a node app with the package.json
like so: 我有一个带有package.json
的节点应用程序,如下所示:
{
"name": "myexpressapp",
"version": "0.0.99",
"scripts": {
"start": "node ./bin/www" },
//etc
}
and in app.js
I have 在app.js
中
console.log ("Running version: "+process.env.npm_package_version);
When I run npm start
in the command prompt this logs 当我在命令提示符下运行npm start
,此日志
Running version: 0.0.99 执行版本:0.0.99
When I start (press F5 ) in VS Code this logs 当我在VS Code中启动(按F5 )时,此日志
Running version: undefined 运行版本:未定义
What change do I need to make to launch.json
to start the app in VS Code as if I had entered npm start
in the command prompt? 我需要对launch.json
进行什么更改,以在VS Code中启动应用程序,就像我在命令提示符下输入npm start
?
I can now get it to run (but not debug) using the following launch.json
: 现在,我可以使用以下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}"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.