In previous post, we have already spent some time on setting up Node JS Base environment. Now we will discuss about how to use Node CLI (Command Line Interface) or Node REPL(Read-Eval-Print Loop) to write and execute some basics Scripts and also discuss about Node JS IDE to write and execute simple Java Script files.
Brief Post Content:
- Login and Exit into/from Node CLI
- Execute JS Files from Node CLI
- Node IDE Setup
- Develop Node JS project from Node IDE
- Execute Node JS project from Node IDE
Login to/Exit from Node CLI
Open command prompt anywhere in your filesystem and execute “node” to login to Node CLI as show below;
process.exit() command to exit from Node CLI as show below.
Execute Simple JS Commands
Output: Hello JournalDEV users
Like this, we can run commands/statements from Node CLI directly and we can see the output on console.
Executing Java Script Files
If we want to run more statements at Node CLI, then we need to run them one by one. But if we write those statements into a JS file, we can run them with just single command. We need to use “node” command to run JS files from Node CLI.
For example, write sample.js file.
var helloJDMessage = "Hello JournalDEV users"; console.log(helloJDMessage);
Use simple Text Editor or any Java Script editor to write this code.
Open command prompt at “D:\NodeJSExamples” and run “Sample.js” file as shown below.
Here we can observe that we are able to print message to console when we run our Sample.js file with node command.
However as a Developer, It’s not good practice to use Text Editors. We should use some Node IDE (Integrated Development Environment) or Tools to ease the Development process and also to reduce Development time and effort.
Now onwards, we are going to use a Node IDE known as “Eclipse Node.js IDE”. Eclipse Node.js IDE is simply known as Enide Studio. In Enide, “E” stands for Eclipse, “n” stands for Node JS and “ide” stands for IDE. We will use Enide latest version “Enide IDE 2014”.
Enide IDE 2014 is a super set of Nodeclipse plugins plus some useful plugins like Angular JS Plugin, RestClient Tool, JSON Editor Plugin, MongoDB Shell Plugin, Gradle Plugin etc. So we are going to use “Enide IDE 2014” Eclipse IDE to develop our Node JS Examples.
If you are Java Developer, I guess you are already familiar with or used Eclipse IDE in your projects.
Enide Studio 2014 IDE Setup
Open your Eclipse IDE and click on “Eclipse Marketplace” from “Help” menu.
It opens Eclipse Marketplace as shown in below image.
Type “enide” in “Find” text box and click on “Go” button. It searches for all available Eclipse software plugins with this name and displays as shown below:
Accept licence and click on “Finish” Button to start installation. Once installation is over, please restart your Eclipse IDE to see these updates. Right click on “Explorer” and select “New” menu option. Now you can see some Node JS Option like “Node JS Project” etc. These are installed as part of Enide Studio installation.
When we open “New” wizard, we can see “Nodeclipse” option as shown below.
If we see those options that mean Enide Studio 2014 installation is done successfully.
If we install Enide Studio 2014 plugin after installing Node JS Base Platform, then this plugin will pick-up all Node JS Platform settings as shown below.
Select “Preferences” option from “Window” menu.
If you install Node JS Platform after this step, please check and set any missing properties in this Preferences wizard.
Develop Node JS Project with Enide Studio Node IDE
Create new Node JS Project by selecting “New >> Other…” from “File” menu.
Select Node.js Project from “New” wizard. Click on “Next” button.
Provide new project name as “sample” and also select “Template to use” as “Hello World”.
Click on “Finish” button. It creates new Node JS Project “sample” and also download libraries.
It automatically changes to “Node” Eclipse Perspective as shown below.
Execute Node JS Project from Node IDE
Execute sample.js file from Enide Studio IDE. Select and Right Click on sample.js file. Select “Run As” >> “Node Application” option.
Observe the output at IDE Console.
Output: Hello JournalDEV Users!
Now we have some idea about how to use Enide Studio IDE to develop and run Node JS Applications with simple Java Script file.
We will discuss how to develop Node JS full-fledged application with Angular JS, Express JS, Mongo DB, RESTful WebServices etc in coming posts.