Node.JS is a new and exciting evented I/O library for V8 JavaScript. While the consensus seems to be to use Cloud9ide.com as the IDE of choice to develop Node.JS applications, this may be impractical for a couple of reasons. First, Cloud9 is an online IDE, which means your source must be hosted on the Internet, either at Cloud9, Bitbucket or Github (I will say that the Github integration @ Cloud9ide.com is pretty nice). Second, it is a rather limited IDE, which means you will have to do your other development elsewhere (if you only develop in JavaScript, than this isn't such a big deal). Finally, the Cloud9ide.com IDE does NOT provide Node.JS code-completion for built-in modules (at least it did not at the time of writing this post). With this in mind, I set out to see how well I could get Node.JS support into Eclipse. Despite these shortcomings, one of the nice things about Cloud9ide.com is that it allows you to run and debug your application in their cloud, making it very easy to test your application. Therefore, my goals for finding desktop IDE support for Node.JS was to make sure that it supported everything that Cloud9ide.com has and more. I settled on the following requirements
- The ability to run/launch Node.JS applications from Eclipse
- The ability to debug Node.JS applications from Eclipse
- Code-completion for Node.JS module
One IDE to Rule Them All
The first piece of the puzzle is to install Node.JS:
- Download the tarball from http://nodejs.org/#download
- Untar/unzip the package with tar –xvf
- Change into the newly created directory
- Run ./configure
- Run make
- Run make install
- Verify node.js is installed by running node –version
- Open Eclipse
- Select Help > Install New Software…
- Click on the “Add…” button
- Enter the following information:
- Name: Eclipse Debugger Plugin for V8 Update Site
- Location: http://chromedevtools.googlecode.com/svn/update/dev/
- Click on “OK” to add the update site
- In the “Work with:” drop-down box, choose “Eclipse Debugger Plugin for V8 Update Site”. The plugin area should now be populated with the plugins offered by the update site.
- Check the box next to “Google Chrome Developer Tools” and click on “Next” to install.
- Walk through the wizard and install the plugin. Restart Eclipse when prompted for the changes to take effect.
- In Eclipse, Select Help > Install New Software…
- Click on the “Add…” button
- Enter the following information:
- Name: VJET Update Site
- Location: https://www.ebayopensource.org/p2/vjet/eclipse
- Click on “OK” to add the update site
- In the “Work with:” drop-down box, choose “VJET Update Site”. The plugin area should now be populated with the plugins offered by the update site.
- Check the box next to “VJET” and click on “Next” to install.
- Walk through the wizard and install the plugin. Restart Eclipse when prompted for the changes to take effect.
- Download the VJET Type Library for Node.JS from http://www.ebayopensource.org/p2/vjet/typelib/NodejsTL.zip
- In Eclipse, select File > Import…
- In the Import wizard, select General > Existing Projects into Workspace
- Select “Next”
- Select the “Select archive file:” import option and click on the “Browse…” button
- Navigate to the location where the NodejsTL.zip file is saved and select it for import.
- Select “Finish” to import the type library.
- Verify that the NodejsTL project appears in your Eclipse workspace.
- In Eclipse, select File > New > Project…
- In the New Project wizard, select VJET > VJET Project and click on the “Next” button.
- On the “Create a VJET Project” screen of the wizard, enter the project name and location (leave the default selections for all other input fields). Click on the “Next” button.
- On the “VJET Settings” screen of the wizard, click on the “Projects” tab.
- Click on the “Add…” button.
- Select the NodejsTL project and click on the “OK” button. This will add auto-completion for NodeJS modules/functions.
- Click on the “Finish” button to create the project
- In Eclipse, select Run > External Tools > External Tools Configurations…
- In the External Tools Configurations window, select the “Program” node in the tree display on the left-hand side of the window.
- Click on the “New launch configuration” button (appears above the tree as a blank piece of paper with a yellow plus sign in the upper right-hand corner). The right-hand side of the window should populate with the launch configuration screen.
- Enter the following information:
- Name: Debug Node
- Location: /usr/local/bin/node
- Working Directory: ${project_loc}
- Arguments: --debug ${resource_name}
- Click on “Apply” to save the changes
- Click on “Close” to exit the “External Tools Configurations” window
- To launch the application, select the “Debug Node” configuration under Run > External Tools. Make sure that the .js file that you would normally pass to Node.JS from the command line is selected in the Script Explorer prior to running. Otherwise, you will get errors when Node.JS runs, as it will not know which file to execute.
- In Eclipse, select Run > Debug Configurations
- In the Debug Configurations window, select the “Standalone V8 VM” node in the tree display on the left-hand side of the window.
- Click on the “New launch configuration” button (appears above the tree as a blank piece of paper with a yellow plus sign in the upper right-hand corner). The right-hand side of the window should populate with the launch configuration screen
- Enter the following information:
- Name: Debug Node 5858
- Host: localhost
- Port: 5858
- Breakpoint sync on launch: Merge local and remote breakpoints
- Click on “Apply” to save the changes
- Click on “Close” to exit the “Debug Configurations” window
- To launch the remote debugger, select the “Debug Node 5858” configuration from the Debug Configurations wizard and click on the “Debug” button. This assumes that the Node.JS process is already running and in debug mode, using the default debug port (5858).
- Change to the VJET JS perspective
- If the VJET JS perspective is not open, open it by selecting Window > Open Perspective > Other…
- Select “VJET JS” from the list and click on the “OK” button.
- Locate the “Debug Node 5858” project that appears in the “Script Explorer” view on the left-hand side of the perspective.
- Expand the project and double click on the source file that you would like to set a breakpoint in to open it in the viewer.
- Right-click to the left of the line that you would like to place a breakpoint on in the file viewer and select “Toggle Breakpoint” to set the breakpoint.
- Interact with the Node.JS application. The application should pause when it hits the breakpoint set in Eclipse.
Node.JS
Using Eclipse as a Node.JS Debugger
Eclipse Debugger Plugin for V8
Eclipse Debugger Plugin for V8 Tutorial
Eclipse Virtual Projects
VJET
Importing VJET JavaScript Type Libraries into Eclipse
Node.JS Step-by-Step
Thanks a lot for this. Not sure why nobody else has commented or liked this, but an awesome post.
ReplyDeleteI'm glad you found it useful!
ReplyDeleteBetter replace
ReplyDelete--debug ${resource_name}
with
--debug ${resource_loc}
Thanks for the tip.
DeleteThanks for this nice article. Please try the latest VJET for resolution to issues between ChromeDevTools debugger and the VJET debugger.
ReplyDeleteThanks Justin. Admittedly, I haven't done a whole lot with VJET in a while (we were evaluating Node.JS as a solution and have since moved in a different direction). I will certainly give the latest VJET a try when I have a chance!
DeleteThanks for great article. It is exactly what I was searching for.
ReplyDeleteI just got a small issue ... it runs the node application, I was able to attach debugger, but I can't toggle breakpoints. The option is disabled. What can be the issue ?
This is probably due to the VJET debugger itself. I don't recall this being an issue when I worked on this in the past, though I haven't been using a more recent version of VJET. If you are not using the latest VJET, you might want to give that a try, per Justin's comment above.
DeleteGot everything working, except that the 'Toggle Breakpoint' option seems to be disabled for some reason. I am using the absolute newest version on VJET (downloaded and installed today). Any hints on what the issue could be. Regardless of that, thanks for the awesome article I've seen writeups struggling to get the point across without screenshots :-)
DeleteThis comment has been removed by the author.
DeleteI get not a valid win32 application ....
ReplyDelete"CreateProcess error=193, %1 is not a valid Win32 application"
Is there win64 bit library available?
thanks for nice article
ReplyDeleteAwesome post. Start to finish - everything explained. Saved about 8 hours time for me. Easily. Thanks.
ReplyDeleteIndeed, a very useful post. Thanks very much!
ReplyDelete