Node JS Hello World Example With Eclipse

This article will show you examples of how to use the Nodeclipse plugin to create and debug node js applications in eclipse.

1. Install Eclipse Node JS Plugin Nodeclipse.

Before you can create a Node.js application in eclipse, you should download and install the 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 the top toolbar.
  2. Input the keyword nodeclipse in the popup window search text box, click the Go button to search. When finding the nodeclipse plugin, click the Install button at its end to install it.
    search-nodeclipse-in-eclipse-marketplace
  3. Check all nodeclipse features in the next dialog and click Confirm button.
  4. Select the accept license agreement radio button in the next dialog.
  5. Click the Finish button to complete the nodeclipse plugin installation.

2. Create Eclipse Node JS Project.

Now you can use eclipse to create a Node.js project follow the below steps.

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

3. Debug Eclipse Node JS Project.

  1. Double click the first column in the hello-world-server.js file in line 3, then it will set a breakpoint there.
  2. Right-click the js file, click Debug As —> Node.js Application menu in the popup menu list. Then the debug process will start. If you meet the below error.

    Failed to connect to Standalone V8 VM
    connect timed out

    debug-node-js-failed-to-connect-v8-vm-error

  3. That is because you use Node.js version 8 or 9 as node runtime. Those two versions are not stable, so you need to follow the below steps to fix the above error.
  4. Download and install Node.js version 7.10.1, please read the article How To Install Node JS In Windows for detail.
  5. Change node app runtime by click eclipse Window —> Preferences menu in the top toolbar.
  6. In the popup window left panel, click JavaScript —> Runtimes menu. In the right panel choose Node.js Runtime in JavaScript Runtimes drop-down list box.
    create-node.js-runtime-environment-in-eclipse-window-preferences
  7. Click Add button to open Add JavaScript Runtime Install popup window.
  8. Select the node.exe file in the Location input box,  give the runtime a name in the Name input box.
    create-node-javascript-runtime-install
  9. Click the Finish button to complete the settings and return to the node runtime list dialog. Check the checkbox before the created runtime and click OK.
  10. Now you can right-click the js file, click Debug As —> Node.js Application menu in the popup menu list. You will find the execution stopped at the first line of the js file. Then you can click debug button at the top toolbar to debug the js files.
0 0 votes
Article Rating
Subscribe
Notify of
guest

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

1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
evelyn
evelyn

I want to use eclipse to create a node js project. And I also want to use the express module in the eclipse node js project.

So I install the Node.js in my Windows OS and install the Node.js express library with the command npm install express, because when I add the -g parameter to install the express library npm install -g express, it failed to install the express library.

I can run node command in widnows dos window successfully. And I write a node js script which implements a single HTTP web server like this article. When I save the node js script file in node installed folder, it can be executed successfully.

Then I installed nodeclipse plugin and create an eclipse Node.js project with empty project template. And I copy my node js script source code into the eclipse node js project.

When I run the node js script in the eclipse node js project, it prompts an error message which said the express module can not be found. How can I fix this issue? I am new to eclipse and Node.js. Thanks.

1
0
Would love your thoughts, please comment.x
()
x