I have a burning question in my head regarding debugging, you see when I am writing Javascript client side I can go to Chrome's console and track my variables and objects etc to see what is happening with my code better.. I am just not able to get my head around about how can we do the same on the server side (node js)? Let's say my front end submitted a form to my express server, how do I go about checking if for instance the req object even received it or not? where do I go about checking variables and objects (debugging) server side code? I definitely can't do it on console of browser as the code exists and executes on the server side so I can't access server side objects etc through browser's console.
我脑子里有一个关于调试的问题,你看我写Javascript客户端的时候我可以去Chrome的控制台跟踪我的变量和对象等,看看我的代码发生了什么更好......我只是不能了解我们如何在服务器端(节点js)做同样的事情?假设我的前端向我的快递服务器提交了一个表单,我该如何检查req对象是否甚至收到它?我在哪里检查变量和对象(调试)服务器端代码?我绝对不能在浏览器控制台上这样做,因为代码存在并在服务器端执行,因此我无法通过浏览器控制台访问服务器端对象等。
5 个解决方案
#1
3
You can still do console.log(). It'll print to the screen where you run the server. However, it's not as good as walking through the code with debugger which you can set breakpoints and do lots of other things debuggers can do. I've used both webstorm's debugger and node-inspector.
你仍然可以做console.log()。它将打印到运行服务器的屏幕上。但是,它不如使用调试器遍历代码那样好,您可以设置断点并执行调试器可以执行的许多其他操作。我已经使用了webstorm的调试器和节点检查器。
You might want to look into node-inspector. The debugger is like Chrome's Dev-Tool, which you might be familiar with. The link below provides everything from installation to tutorials.
您可能希望查看node-inspector。调试器就像Chrome的开发工具,你可能会熟悉它。下面的链接提供从安装到教程的所有内容。
https://github.com/node-inspector/node-inspector
https://github.com/node-inspector/node-inspector
#2
1
Node comes with a REPL (Read-Eval-Print-Loop). It works a bit like the console of chrome but requires a bit of configuration and set up of it's scope.
节点附带REPL(读取 - 评估 - 打印 - 循环)。它的工作方式有点像chrome的控制台,但需要一些配置并设置它的范围。
Here is an example: http://derickbailey.com/2014/07/02/build-your-own-app-specific-repl-for-your-nodejs-app/
这是一个例子:http://derickbailey.com/2014/07/02/build-your-own-app-specific-repl-for-your-nodejs-app/
#3
0
if you do console.log to variables and objects you can see it on you command prompt from where you are running your server
如果你将console.log用于变量和对象,你可以在运行服务器的命令提示符下看到它
#4
0
The console.log() has 2 kinds:
console.log()有2种:
- When it write in the client codes. It will console the message on your brower.
- 当它写入客户端代码时。它将在您的浏览器上控制消息。
- When it write in the server codes. It will console the message on your editor such as Webstorm.
- 当它写入服务器代码时。它将在您的编辑器上控制消息,例如Webstorm。
Suggest use debug to check variables and objects instead of using console.log() because it's more convenient.
建议使用debug来检查变量和对象,而不是使用console.log(),因为它更方便。
#5
0
You might want to consider webstorm
. It has advanced debugging
support built-in for nodejs which allows you to set breakpoints just like in Chrome's debugging tools.
您可能想要考虑webstorm。它具有内置的nodejs高级调试支持,允许您像在Chrome的调试工具中一样设置断点。
#1
3
You can still do console.log(). It'll print to the screen where you run the server. However, it's not as good as walking through the code with debugger which you can set breakpoints and do lots of other things debuggers can do. I've used both webstorm's debugger and node-inspector.
你仍然可以做console.log()。它将打印到运行服务器的屏幕上。但是,它不如使用调试器遍历代码那样好,您可以设置断点并执行调试器可以执行的许多其他操作。我已经使用了webstorm的调试器和节点检查器。
You might want to look into node-inspector. The debugger is like Chrome's Dev-Tool, which you might be familiar with. The link below provides everything from installation to tutorials.
您可能希望查看node-inspector。调试器就像Chrome的开发工具,你可能会熟悉它。下面的链接提供从安装到教程的所有内容。
https://github.com/node-inspector/node-inspector
https://github.com/node-inspector/node-inspector
#2
1
Node comes with a REPL (Read-Eval-Print-Loop). It works a bit like the console of chrome but requires a bit of configuration and set up of it's scope.
节点附带REPL(读取 - 评估 - 打印 - 循环)。它的工作方式有点像chrome的控制台,但需要一些配置并设置它的范围。
Here is an example: http://derickbailey.com/2014/07/02/build-your-own-app-specific-repl-for-your-nodejs-app/
这是一个例子:http://derickbailey.com/2014/07/02/build-your-own-app-specific-repl-for-your-nodejs-app/
#3
0
if you do console.log to variables and objects you can see it on you command prompt from where you are running your server
如果你将console.log用于变量和对象,你可以在运行服务器的命令提示符下看到它
#4
0
The console.log() has 2 kinds:
console.log()有2种:
- When it write in the client codes. It will console the message on your brower.
- 当它写入客户端代码时。它将在您的浏览器上控制消息。
- When it write in the server codes. It will console the message on your editor such as Webstorm.
- 当它写入服务器代码时。它将在您的编辑器上控制消息,例如Webstorm。
Suggest use debug to check variables and objects instead of using console.log() because it's more convenient.
建议使用debug来检查变量和对象,而不是使用console.log(),因为它更方便。
#5
0
You might want to consider webstorm
. It has advanced debugging
support built-in for nodejs which allows you to set breakpoints just like in Chrome's debugging tools.
您可能想要考虑webstorm。它具有内置的nodejs高级调试支持,允许您像在Chrome的调试工具中一样设置断点。