Now let us see how to install node.js.
Download node.js for windows at https://nodejs.org/en/
Run the exe file which will install the node.js which comes with npm (node package manager)
Now You should be able to run both node and npm commands on command prompt
Suppose node.js installed on C:\Program Files\nodejs
then npm will be located on C:\Program Files\nodejs\node_modules\npm\bin
note : nodejs should be in windows path. You can check it with path command.
Test both npm and node installation by entering the commands at command prompt as given below
Usage: npm <command>
where <command> is one of:
access, add-user, adduser,…
Now you will be able to run any node application.
Now let us create and run a node application using command prompt
Node Application in Command Prompt
Make a folder
c:\node_example>create a text file and write the below code
console.log("Hi Welcome to Node.js Hello World");
var d = new Date();
console.log("Current Date is: " + ("0" + (d.getDate() + 1)).slice(-2)+"/"+("0" + (d.getMonth() + 1)).slice(-2)+"/"+d.getFullYear());
console.log("Current Time is: "+ d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds());
and save it as helloworld.js
Now run the node application by running the below command on command prompt
Now let us see How to create node.js application in Eclipse
Node Application in Eclipse
Before creating a node.js project, we need to install nodeclipse plugin for eclipse so that we can develop and run node.js application in eclipse ide.
To install nodeclipse plugin, follow the below steps
Open Eclipse and access the menu Help->Eclipse Marketplace
type nodeclipse in the find box and search which will list the nodeclipse, the eclipse plugin for Node.js
Now select install and restart eclipse after the installation is complete.
At command prompt, run the below command
C:\node_example>npm install -g nodeclipse
Output of the above command:
C:\Users\vkj\AppData\Roaming\npm\epm -> C:\Users\vkj\AppData\Roaming\npm\node_modules\nodeclipse\bin\epm.js
C:\Users\vkj\AppData\Roaming\npm\nodeclipse -> C:\Users\vkj\AppData\Roaming\npm\node_modules\nodeclipse\bin\nodeclipse.js
C:\Users\vkj\AppData\Roaming\npm\nci -> C:\Users\vkj\AppData\Roaming\npm\node_modules\nodeclipse\bin\nci.js
└── email@example.com (firstname.lastname@example.org, email@example.com)
Now plugin installation is complete.
To create node project in eclipse, create a folder (for eg. node_example) where you want to create node application and type the below command on the command prompt
Now Add the above project in Eclipse
File -> Import… -> General / Existing Projects into Workspace
and enter project directory: C:\node_example
Click on finish