10

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.

approxiblue
  • 6,982
  • 16
  • 51
  • 59
mysamza
  • 387
  • 1
  • 6
  • 22

5 Answers5

4

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.

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.

https://github.com/node-inspector/node-inspector

Ben
  • 5,024
  • 2
  • 18
  • 23
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.

Here is an example: http://derickbailey.com/2014/07/02/build-your-own-app-specific-repl-for-your-nodejs-app/

Ross
  • 14,266
  • 12
  • 60
  • 91
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

ricky
  • 1,644
  • 1
  • 13
  • 25
0

The console.log() has 2 kinds:

  1. When it write in the client codes. It will console the message on your brower.
  2. When it write in the server codes. It will console the message on your editor such as Webstorm.

Suggest use debug to check variables and objects instead of using console.log() because it's more convenient.

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.

Kunal Kapadia
  • 3,223
  • 2
  • 28
  • 36