Node JS Hello World Example With Eclipse

This article will show you examples about how to use nodeclipse plugin to create and debug node JavaScript application in Eclipse.

1. Install Nodeclipse Eclipse Plugin.

Before you can create node js application in eclipse, you should download and install Nodeclipse plugin in your Eclipse. Eclipse version is eclipse-jee-neon-3-win32-x86_64. Nodeclipse plugin version is 1.0.2.

  1. Open Eclipse, click Help —> Eclipse Marketplace menu in top toolbar.
    help eclipse marketplace menu item
  2. Input nodeclipse in the popup window search text box, click Go button to search. When find the nodeclipse plugin in below picture click Install button at it’s end.
    search nodeclipse in eclipse marketplace
  3. Check all nodeclipse features in the next dialog and click Confirm button.
    install nodeclipse components selection
  4. Check accept license agreement in next dialog.
    agree nodeclipse install license aggrement
  5. Click Finish button to complete the nodeclipse plugin installation.

2. Create Node Project.

Now you can create node project follow below steps.

  1. Eclipse File —> New —> Project menu. Input node in Wizards search box, then select Node.js Project.
    create node.js project in eclipse
  2. In next dialog, input the project name and select default workspace. Select Hello World radio button in Template to use section.
    node js project settings in eclipse
  3. Click Finish button to complete the node.js project creation. Then you can see the wizard added files in left project panel. Click hello-world-server.js file in the file list, it is just implement a simple http web server.
    hello world node.js project file structure

3. Debug Node JS Project.

Double click the first column in hello-world-server.js file in line 3, then it will set a breakpoint at there.

set breakpoint in hello world node.js file

Right click the js file, click Debug As —> Node.js Application menu in popup menu list. Then the debug process will start. If you meet below error.

Failed to connect to Standalone V8 VM
connect timed out

debug node js failed to connect v8 vm error

That is because you use node.js version 8 or 9 as node runtime. Those two versions are not stable, so you need follow below steps to fix above error.

  1. Download and install node.js version 7.10.1, please read article How To Install Node JS In Windows for detail.
  2. Change node app runtime by click Window —> Preferences menu in top tool bar.
    click window preferences menu
  3. In popup window left panel, click JavaScript —> Runtimes menu. In right panel choose Node.js Runtime in JavaScript Runtimes drop down list box.
    create node.js runtime environment in eclipse window preferences
  4. Click Add button to open Add JavaScript Runtime Install  popup window, select node.exe file in Location input box,  give the runtime a name in Name input box.
    create node javascript runtime install
  5. Click Finish button to complete the settings and return to node runtime list dialog. Check the checkbox before the created runtime and click OK.
    create node.js runtime environment in eclipse window preferences
  6. Now you can right click the js file, click Debug As —> Node.js Application menu in popup menu list. You will find the execution stopped at the first line of the js file. Then you can click debug button at top tool bar to debug the js files.
    debug javascript file toolbar menu

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.