Now node. JS is doing the best in single-step debugging, counting IntelliJ idea, but node cannot start debugging when using cluster, and StackOverflow has a description and answer to this question (click here to see). But the solution here is to implement debugging by increasing the startup parameter control and abandoning the multi-process mode, such as starting a single process at local testing and using multiple processes in an operational environment.
You can read environment variables in node. js by using process.env.环境变量名
the method, which means that you can control whether multiple processes are enabled in the following ways:
if (process.env.DEBUG_LOCAL == ‘true‘) { //单进程代码处理} else { //cluster代码处理}
Code 1.1
The rest is to configure the environment variables in idea, click the Debug Configuration function, that is, click on the figure 1.1 position.
Figure 1.1 Selecting a configuration
Click the environment Variable Configuration function button in the Open interface
Figure 1.2 Configuration Interface
Add an environment variable
Figure 1.3 Adding environment variables
This completes the configuration, after clicking Debug, will run the current code into a single process, in the production environment without the environment variable start, then run into the normal cluster code.
debugging child processes in node