如何使用VS Code调试ExpressJS?

时间:2019-02-13 18:43:41

标签: express visual-studio-code vscode-debugger

关于如何使用VS Code调试ExpressJS应用程序,有零篇好的著作。 我想做的是nodemon index.js我的快速应用程序。然后在VS Code开放式Chrome的index.js文件中设置我的断点,导航到https://myapp:4000并期望我的断点被击中。

这是到目前为止我在launch.json中尝试过的一切。

{
  "name": "Launch",
  "type": "node",
  "request": "launch",
  "program": "${workspaceFolder}/server/express-api/index.js",
  "stopOnEntry": true,
  "args": [],
  "cwd": "${workspaceFolder}",
  "preLaunchTask": null,
  "runtimeExecutable": null,
  "runtimeArgs": [
    "--nolazy"
  ],
  "env": {
    "NODE_ENV": "development"
  },
  "console": "internalConsole",
  "sourceMaps": false
},
{
  "type": "chrome",
  "request": "attach",
  "name": "Attach to Chrome",
  "url": "https://myapp",
  "port": 4000,
  "webRoot": "${workspaceFolder}"
}

{
  "type": "node",
  "request": "launch",
  "name": "Launch Program",
  "protocol": "inspector",
  "runtimeExecutable": "nodemon",
  "runtimeArgs": [
    "--inspect=4000"
  ],
  "program": "${workspaceFolder}/server/express-api/index.js",
  "port": 4000,
  "restart": true,
  "env": {
    "NODE_ENV": "development"
  },
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen"
},
{
  "type": "chrome",
  "request": "attach",
  "name": "Launch Chrome",
  "port": 9222,
  "url": "ws://127.0.0.1:4000",
  "webRoot": "${workspaceFolder}/server/express-api/index.js"
}

我的目录结构是这样的

${workspaceFolder}/client/ <-- angular app created with angular-cli
${workspaceFolder}/server/express-api/ <-- holds the index.js and all the route files

我的express api提供了我的angular-cli构建文件。 而我的express api已被提供

const app = express();
const https = require('https');
const httpsServer = https.createServer(credentials, app);
httpsServer.listen(4000, 'myapp', () => console.log('app running');

我在做什么错了?

0 个答案:

没有答案