简体   繁体   English

如何在客户端和服务器之间无缝调试javascript

[英]How can I debug javascript between client and server seamlessly

Question regarding javascript debugging: 有关javascript调试的问题:

We have a mobile app, made with JavaScript and HTML. 我们有一个使用JavaScript和HTML制作的移动应用程序。 This app is running on the mobile platform (BlackBerry 10, Android, iOS) inside a web container. 该应用程序在Web容器内的移动平台(BlackBerry 10,Android,iOS)上运行。

There is another part of this application running on the remote server. 该应用程序的另一部分在远程服务器上运行。 This part is implemented also with JavaScript running on Node.js. 这部分也可以通过在Node.js上运行的JavaScript来实现。

Assume there is some communication established between the client (JS on mobile) and the server (JS on Node.js) sides using eg REST. 假设使用REST在客户端(移动JS)和服务器(Node.js JS)之间建立了某种通信。

The question I would like to know is if it is possible to seamlessly debug both sides at the same time. 我想知道的问题是,是否有可能同时无缝调试双方。 Eg if I have a breakpoint on the mobile app client side, how would I be able to debug all the way to JS on the server side, if it's possible at all. 例如,如果我在移动应用程序客户端有一个断点,那么如果有可能的话,我将如何调试服务器端的JS。

Any suggestions would help. 任何建议都会有所帮助。

You can use node-inspector on the server, then you'll have TWO instances, but the same debugger toolset. 您可以在服务器上使用node-inspector,然后将有两个实例,但是具有相同的调试器工具集。

If you're stepping through code client, and want to debug "into" the server, you must place a breakpoint in the server debugger before making the GET/POST from the client. 如果您单步执行代码客户端,并且想调试到服务器中,则必须在服务器调试器中放置一个断点,然后才能从客户端进行GET / POST。

TIP: Get a three (at least two) monitor setup. 提示:获得三个(至少两个)监视器设置。

Using the node inspector is a good strategy for doing debugging, but it would also be good to supplement the debugger with logging. 使用节点检查器是进行调试的好方法,但是用日志记录补充调试器也是很好的。

Debugging will let you step through an event chain and examine values of variables and output of functions in that chain, but in production it won't give you insight into the steps or production conditions that lead to errors users are experiencing (ie Why do I have a null variable? Why is my response message wrong?) If you use debugging without logging you'll be trying to replicate the conditions in production that are causing an error, which is an inefficient (and usually futile) way of doing things. 调试将使您逐步浏览事件链,并检查该链中变量的值和函数的输出,但是在生产中,它无法让您深入了解导致用户遇到错误的步骤或生产条件(即,为什么我有一个空变量?为什么我的响应消息是错误的?)如果使用调试而不记录日志,您将尝试复制生产中导致错误的条件,这是一种低效(通常是徒劳的)工作方式。

I'd say the best way to implement what you want to do (solve issues taking into account client & server events that happen concurrently) is to implement an open source logging library like Log4j on both your server and your client and configure an appender to send the logs to a log aggregator like Loggly which gives you tools to analyze both client & server logs in the same place (rather than extracting log files from both devices manually). 我想说的是,实现您想要做的事情的最佳方法(解决同时考虑到客户端和服务器事件的问题)是在服务器和客户端上实现一个开源日志记录库,例如Log4j,并配置一个附加程序以将日志发送到Loggly之类的日志聚合器,该工具为您提供工具来分析同一位置的客户端和服务器日志(而不是手动从这两个设备中提取日志文件)。

Once you've done this, you'll be able to distribute your application out to testers and you'll be able to see what actions, application logs, and hardware/network conditions surround certain issues. 完成此操作后,就可以将应用程序分发给测试人员,并且可以查看某些问题涉及哪些操作,应用程序日志和硬件/网络状况。 With this data in hand you'll know a lot better what leads to certain bugs and can use that information to much more effectively use node-inspector to debug them. 掌握了这些数据,您将更好地了解导致某些错误的原因,并可以使用该信息更有效地使用节点检查器对其进行调试。

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

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