NodeJS Tutorial :: Part-1

Install nodejs

Download nodejs LTS version from here

After installing it, open CMD and check nodejs version by following command:
node --version

If showing version, then nodejs has been installed successfully

Install IDE

We will install Visual Studio Code as IDE because this is very light, more friendly and support most of the plugins for nice development experience.

Download VSC from here

While install, check all of the check-boxes

First Program

Create a new folder. Give it any name

open the blank folder with visual studio

Open the terminal. Go to Terminal > New Terminal
Hit the following command:

npm init -y

package.json will be generated

create a new flle name hello.js

Write following code:

console.log('Hello world')

Now hit following command to run the program:
node hello.js

Output: Hello world


Variables are used for storing data.

For example, var name=”Hasan”; var number=10;

Here, name and number are variable

Using let and const (ES6)

Before 2015, using the var keyword was the only way to declare a JavaScript variable.

JavaScript (ES6) allows the use of the const keyword to define a variable that cannot be reassigned, and the let keyword to define a variable with restricted scope.

Variable writing rules

  1. All variable names must begin with a letter of the alphabet or an. underscore( _ )
    For example: myVariable, _number
  2. One phrase variable should be small and two phrase variable name should be camelCase
  3. One phrase variable example: name
    Two phrases variable example: firstName
  4. Variable name should not be start with number.
    For example: 2username  can not be used
  5. After the first initial letter, variable name can also contain letters and numbers.
    For example: userName1, userName2
  6. Uppercase characters are different from lowercase characters.
    For example: a and A are different variables
  7. You cannot use JavaScript reserved keywords as a variable name. For example: let. var, const etc
  8. Space or special characters are not allowed in variables.
    For example: first name, first#name, first@name

User Input

install this package:

nmm i prompt-sync

write following code:

const prompt=require('prompt-sync')();

let name=prompt('Enter your name: ')

Hit following command:

node hello.js

Output: Enter your name: Salman


Use // to comment a line or multiple line

const prompt=require('prompt-sync')();

//input your name
let name=prompt('Enter your name: ')

Identifiers (let, var, const)

let and const both used in JS es6 version
let: used in local scope (also you can use it globally)
var: used in global scope (also you can use it locally)
const: used only for assigning constant variables. Constant means the variable value will not be changed or assigned.


There are 6 types of datatype in JavaScript

  1. Number
  2. String
  3. Boolean
  4. BigInt
  5. Symbol
  6. Undefined

For example,
var number= 10; // Number
var name= “Salman”; // String
var obj = {firstName:”Salman”, lastName:”Srabon”};    // Object

Checking Datatypes

let name="Rahim";
Output: string
let value=1.5;
Output: number
let bool=true;
Output: boolean

Parsing Datatypes

To convert integer type digits to string:


To convert string type digits to integer:


To convert string type digits to float:


To convert float type to integer:


To fix the decimal value:


To precise the decimal value:


String concat

“+” plus operator will be used to concat two or multiple variables.

let firstName="Shakib";
let lastName="Khan";
console.log(firstName+" "+lastName)

`${}` sign will be used to concat variables values in a string.

let firstName="Shakib";
let lastName="Khan";
console.log(`${firstName} ${lastName}`)

JS Operators

There are 6 types of operators

  1. Assignment operators
  2. Comparison operators
  3. Logical operators
  4. Type operators
  5. Bitwise operators
  6. Arithmetic operators

Assignment Operators

=x = y
+=x += y
-=x -= y
*=x *= y
/=x /= y
%=x %= y
**=x **= y

Comparison Operators

==equal to
===equal value and equal type
!=not equal
!==not equal value or not equal type
>greater than
<less than
>=greater than or equal to
<=less than or equal to

Logical Operators

&&logical and
||logical or
!logical not

Type operators

typeOf()Returns the type of a variable
instanceOf()Returns true if an object is an instance of an object type

Bitwise Operators

OperatorDescriptionExampleSame asResultDecimal
&AND5 & 10101 & 00011 1
|OR5 | 10101 | 0001101 5
~NOT~ 5 ~01011010 10
^XOR5 ^ 10101 ^ 0001100 4
<<Zero fill left shift5 << 10101 << 11010 10
>>Signed right shift5 >> 10101 >> 110  2
>>>Zero fill right shift5 >>> 10101 >>> 110  2

Arithmetic Operators

OperatorDescriptionExampleSame asResultDecimal
&AND5 & 10101 & 00011 1
|OR5 | 10101 | 0001101 5
~NOT~ 5 ~01011010 10
^XOR5 ^ 10101 ^ 0001100 4
<<Zero fill left shift5 << 10101 << 11010 10
>>Signed right shift5 >> 10101 >> 110  2
>>>Zero fill right shift5 >>> 10101 >>> 110  2

Necessary Math Functions

Getting absolute value:
Getting power of a number:
Getting square root of a number:
Getting random number:
Getting max/min from numbers:

about author


If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

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