In this post I’ll help understand how can debugging a Node.js application from scrach.
You need installed in you computer the following tolls:
- Node.js (make sure that you have access a node command in your command line tool)
Create a Simple Node.JS application
First, we’ll install express.
npm install -g express
-g flag means that you are installing express globally on your system.
So, now we are available for create a node.js application using express.
express -c stylus express-app-sample
-c states that we want to use stylus for css.
The next step, is install the app dependencies. So, we need enter express-app-sample folder and install. We can do that with the following commands:
And now we’re available for running our app. What we need to do is the following command.
You should see
Express server listening on port 3000 and if you open http://localhost:3000 you’ll see the default Express page.
Debugging Node.js application using Eclipse
Install Eclipse debugger plugin for V8
With Eclipse debugger plugin for V8 we can easy used for debugging node applications. This is the steps to install the plugin on Eclipse:
- Select the menu item Help > Install New Software…
- Click on Add… button.
- In the textbox labeled Name: enter Google Chrome Developer Tools. In the textbox labeled Location: enter http://chromedevtools.googlecode.com/svn/update/dev/. Click OK.
- Select Google Chrome Developer Tools – http://chromedevtools.googlecode.com/svn/update/dev/ from the combo box Work with.
- Click the checkbox next to Google Chrome Developer Tools in the table. And Click the button labeled Next >.
- Accept the terms of the license agreement and click the button labeled Finish.
Eclipse will restart with the V8 Eclipse Debugging Plugin installed.
Debug node.js application
- Using node.js command line, we’ll launch our app on debug mode, using the following command:
node --debug=5858 app.js
- In the Menu, choose Window > Open Perspective > Other, then select Debug from the list and click OK, to ensure we are viewing the debug perspective.
- Click the drop box button next to the green bug one and select “Debug Configurations …” option.
- Start the debugging by clicking “Debug” button. If everything goes well, we’ll get something like this:
- So, we just need to put breakpoints on the project that appears when we start debugging, in the Project Explorer, to debug.
NOTE: You can find out more about debugging node.js applications using Eclipse in this link.