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.
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.
Share Improve this question edited Oct 15, 2015 at 5:55 approxiblue 7,12216 gold badges52 silver badges59 bronze badges asked Oct 15, 2015 at 5:31 mysamzamysamza 3972 gold badges6 silver badges22 bronze badges5 Answers
Reset to default 4You 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./node-inspector/node-inspector
Node es 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./2014/07/02/build-your-own-app-specific-repl-for-your-nodejs-app/
if you do console.log to variables and objects you can see it on you mand prompt from where you are running your server
The console.log() has 2 kinds:
- 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.
Suggest use debug to check variables and objects instead of using console.log() because it's more convenient.
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.