简体   繁体   English

使用WebStorm使用来自单独客户端应用程序的调用进行Node Express App调试

[英]Node Express App debugging with calls from separate client app using WebStorm

I've looked around and had a lot of trouble figuring this out. 我环顾四周,在解决这个问题时遇到了很多麻烦。 I'm hoping someone might be able to point me to a post or have information on how to do this. 我希望有人可以将我指向某个帖子,或者提供有关如何执行此操作的信息。

My problem is that I have 2 projects I've made using WebStorm: 我的问题是我有两个使用WebStorm进行的项目:

  • I have 1 application that is my server-side code running on port 3000. It's a simple Node Express app. 我有1个应用程序,它是在端口3000上运行的服务器端代码。它是一个简单的Node Express应用程序。
  • The second application is an Angular 4 / Ionic 3 application running the client side on port 8100. 第二个应用程序是在端口8100上运行客户端的Angular 4 / Ionic 3应用程序。

I want to run my server application in debug mode, so that it hits the breakpoints for all the data being sent from the client side app. 我想在调试模式下运行服务器应用程序,以便它能到达从客户端应用程序发送的所有数据的断点。

For example: Angular / Ionic app sends a get request for all clients for a given customer. 例如:Angular / Ionic应用程序为给定客户的所有客户发送获取请求。 The customer is sent via url parameter. 通过url参数发送客户。 I want the server code to pause when it receives this request and so I can see this URL parameter. 我希望服务器代码在收到此请求时暂停,因此我可以看到此URL参数。 Fairly simple. 很简单。

The server is also using grunt to build the project, and nodemon to watch it. 服务器还使用grunt来构建项目,并使用nodemon对其进行监视。 I'm using some npm scripts to make life easy. 我正在使用一些npm脚本来简化生活。 Here are the scripts: 以下是脚本:

"scripts": {
  "dev": "SET NODE_ENV=development && nodemon ./bin/www",
  "grunt": "grunt",
  "start": "node ./bin/www"
},

Nothing fancy. 没有什么花哨。

I have WebStorm configured to run my scripts from hitting play. 我已将WebStorm配置为从击中运行我的脚本。 So the play button will first run the following sequence: 因此,播放按钮将首先按以下顺序运行:

  1. npm run grunt
  2. npm run dev

Again ... nothing fancy. 再次...没有幻想。

Now how do I get this thing to setup a debugger so I can listen in WebStorm? 现在如何获得此东西来设置调试器,以便可以在WebStorm中收听? I have a both projects open in separate windows, and I am initiating the calls to the server from the client. 我有两个项目都在单独的窗口中打开,并且正在从客户端启动对服务器的调用。 How do I make the break points grab hold and show me the data coming into the server? 如何使断点抓住并向我显示进入服务器的数据?

I feel like this is incredibly easy and I'm missing something really stupid. 我觉得这非常容易,而且我缺少真正愚蠢的东西。 Any help would be much appreciated. 任何帮助将非常感激。

You need starting you server in debugger to get breakpoints in your server code hit. 您需要在调试器中启动服务器,才能在服务器代码命中获得断点。 If you prefer to start your app via npm script, you have to add $NODE_DEBUG_OPTION (or %NODE_DEBUG_OPTION% on Windows) to make sure that Node.js is started with appropriate debug options ( --debug-brk , --inspect-brk , etc) 如果您希望通过npm脚本启动应用程序,则必须添加$NODE_DEBUG_OPTION (或在Windows上为%NODE_DEBUG_OPTION% ),以确保使用适当的调试选项( --debug-brk ,-- --inspect-brk )启动--inspect-brk等)

So: 所以:

  • in package.json, modify your dev script as follows: 在package.json中,如下修改您的dev脚本:

"dev": "SET NODE_ENV=development && nodemon %NODE_DEBUG_OPTION% ./bin/www"

  • right-click your package.json, choose Show npm scripts 右键单击您的package.json,选择显示npm脚本
  • right-click dev script in npm tool window that opens, choose edit 'dev' settings to create a run configuration. 在打开的npm工具窗口中右键单击dev脚本,选择edit'dev'设置以创建运行配置。
  • open your source files in editor, add breakpoints 在编辑器中打开源文件,添加断点
  • press Debug to start debugging Debug开始调试
  • run your client app, initiate the calls to the server 运行您的客户端应用程序,启动对服务器的调用

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM