nodejs开发中如何调试基于多进程的程序
2015-04-05 16:47
567 查看
在nodejs开发中,通过child_process启动多进程时,能够在启动的同时直接启动不同的调试端口:这段程序是从5588自增1为每个进程都设置了唯一的端口:
1.如果使用以上方法出现websotrm调试时,仍然不进入断点,webstorm在启动调试后不继续的情况,请把webstorm中的node的路径换成以下内容的sh文件 [同时安装socat],社区中说是webstorm的一个bug。
本文出自 “似水流年” 博客,请务必保留此出处http://lonely7345.blog.51cto.com/5605849/1428096
var globalI = 0; var DEBUG_BRK = '--debug-brk', IS_DEBUGGING = isDebugging(); function isDebugging() { var execArg, port; for (var i = 0; i < process.execArgv.length; i++) { execArg = process.execArgv[i]; var debugBrkWithPort = DEBUG_BRK + '='; if (execArg.indexOf(debugBrkWithPort) === 0) { port = parseInt(execArg.substring(debugBrkWithPort.length)); if (!isNaN(port)) { return true; } } } return false; } function addDebugParameter(args) { if (IS_DEBUGGING) { globalI++; args.splice(0, 0, DEBUG_BRK +"="+ (5588+globalI)); } };在fork的同时调用 :
var processParameters = [path]; addDebugParameter(processParameters); var sub=require('child_process').fork(path, obj.bindings[name].args, { 'cwd' : process.cwd(), 'env' : env, execArgv:processParameters });注意:
1.如果使用以上方法出现websotrm调试时,仍然不进入断点,webstorm在启动调试后不继续的情况,请把webstorm中的node的路径换成以下内容的sh文件 [同时安装socat],社区中说是webstorm的一个bug。
ORIG_PORT=`echo $* | sed 's/.*--debug-brk=\([0-9]*\).*/\\1/'` NEW_PORT=`expr $$ "%" 64000 + 1024` ARGS=`echo $* | sed "s/--debug-brk=[0-9]*/--debug-brk=$NEW_PORT/"` node $ARGS & if ["$ORIG_PORT" -lt ""];then node $ARGS & else node fi sleep 1 if ["$ORIG_PORT" -lt ""];then socat TCP4-LISTEN:$ORIG_PORT,fork,bind=127.0.0.1 TCP:localhost:$NEW_PORT else socat TCP4-LISTEN:$ORIG_PORT,fork,bind=127.0.0.1 TCP:localhost:$NEW_PORT fi2.如果使用chrome进行调试,请更换DEBUG_BRK
本文出自 “似水流年” 博客,请务必保留此出处http://lonely7345.blog.51cto.com/5605849/1428096
相关文章推荐
- nodejs开发中如何调试基于多进程的程序
- Android 软件开发之如何使用Eclipse Debug调试程序详解(十二)
- 如何基于BS架构开发聊天程序
- Android 软件开发之如何使用Eclipse Debug调试程序详解
- Android 软件开发之如何使用Eclipse Debug调试程序详解
- C# 开发技巧]如何防止程序多次运行 线程 进程
- Android 软件开发之如何使用Eclipse Debug调试程序详解
- RMI网络编程开发之二 如何搭建基于JDK1.5的分布式JAVA RMI 程序
- Android 软件开发之如何使用Eclipse Debug调试程序详解
- 在Windows Mobile和Wince(Windows Embedded CE)下如何使用.NET Compact Framework开发进程管理程序
- IOS开发 如何联机调试和发布程序(99$)
- Android 软件开发之如何使用Eclipse Debug调试程序详解
- IOS开发 如何联机调试和发布程序(99$) -转载
- Android 软件开发之如何使用Eclipse Debug调试程序详解(十二)
- Android 软件开发之如何使用Eclipse Debug调试程序详解(十二)
- 如何基于BS架构开发聊天程序
- 如何基于BS架构开发聊天程序
- C# 开发技巧]如何防止程序多次运行 线程 进程
- Android 软件开发之如何使用Eclipse Debug调试程序详解