Let’s Start with the Hello World in Node JS
How to Install Node.js:
· Direct to the Link - Download Node.js
· Download the Latest version and Install it in the System.
After Installing the Node.js We start directly
· Open Notepad or any Code Editor tools of your choice.
· Here am using Notepad++.
· Let’s start to write code to print hello world in the console. Type the below line in the code editor.
console.log (‘Hello World..!’)
· Save the file with .js extension
o Example: filename.js
· Now open the command prompt and route/direct to the file stored directory.
· In CMD type > to run the file and see the output
o Type > node filename.js and press enter.
o You would See the Output Screen which will print the Hello World.
· Viola! You completed the hello world program in NodeJS.
· Yes, that’s it. Simple isn’t it?
To Get quick glance on how to use check the below examples …
Example 1:
How to Write “Hello World!” in NodeJS?
Syntax:
console.log (“statement”);
Source code:
console.log (‘Hello World..!’)
Output:
Hello World…!
Noteworthy: In NodeJS Semicolon (;) is optional.
Example 2:
How to add two numbers in NodeJS?
Source code:
var a=10
var b=10
var c
c=a+b
console.log(“C Values is:”,c)
Output:
C Values is: 20
Noteworthy: var is datatype which is used to declare the variables.
Example 3:
Let’s see how to use the if statement in Nodejs
Syntax:
if (condition){
/*statements*/
}
else{
/*statements*/
}
Source code:
var a=10
if(a==10){
console.log("Values is 10")
}
else{
console.log("Values is not 10")
}
Output:
Values is 10
Thank you, Come Back to Learn More About Tech Stuff with Tech Bird
Have A Nice Day !
:)
Comments