Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

21 BasicsofNodeJS

The document provides an introduction to Node.js including what it is, its capabilities and uses. It discusses how Node.js allows JavaScript to be used for server-side development and some development tools. It also provides examples of using Node.js to work with variables, arrays, objects and more complex JSON structures.

Uploaded by

sandeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

21 BasicsofNodeJS

The document provides an introduction to Node.js including what it is, its capabilities and uses. It discusses how Node.js allows JavaScript to be used for server-side development and some development tools. It also provides examples of using Node.js to work with variables, arrays, objects and more complex JSON structures.

Uploaded by

sandeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Introduction to Node.

js:

Node is an open-source, Cross Platform, Java script runtime environment and used for executing Java
Script code outside web browser.

Can we use java script for server side? - Yes


Why do we have to learn two programming languages? For front and back

Node.js is a great web framework for beginners because it works great for data-intensive applications,
like streaming and real-time apps, and Node.js makes it easy to start building backend.
Capabilities of Node.js , it is used to build below Applications
- Build Application Logic
- Web Server
- Send Email
- DB lookups
- Automations
- Outputs
- Host Web Apps

Nodes echo system is npm, we get millions of reusable modules.


It’s a Asynchronous ,non-blocking i/o programming language.

Java, ABAP executes line by line.

Development tools:
BAS
VSCODE- Free tool provided by Microsoft. Its gives thousands of plug ins, makes of life of
developer is easy.
Download and install node js - https://nodejs.org/en/
Test if its available
node -v

To test
node sample.js
Its case sensitive

Cls command to clear console.


Typeof is a builtin function used to check data type

Select the block of code, and use ctrl + / to comment the code
parseInt
console.log("Hello node.js by Sandeep");
var x = 10;// this will create variable x of type number
console.log(x);
console.log(typeof(x));

var y = "10";
console.log('y is of type :' + typeof(y));

y = parseInt(y);
console.log('y is of type :' + typeof(y));

z = false;
console.log('z is of type :' + typeof(z));

// Array is collectin of values


//[]-bracket
//()-paranthesis
//{}-braces

var aFruits = ["Apple","banana", "cherry"];


console.log(aFruits);

//Display First item of array


console.log("First Item:" + aFruits[0]);
// Last item pf array
console.log("Last Item:" + aFruits[aFruits.length-1]);
// Append item to the array
console.log("After adding new item:" + aFruits.push("PineApple"));
console.log("my array is now ---->" + aFruits);
// insert item in middle
console.log(aFruits.splice(1,0,"Mango"));
//After inserting item at index 1
console.log("After adding fruits at index 1 ---->" + aFruits);
//Remove from middle
console.log(aFruits.splice(2,1));
console.log("After remove at index 2 ------->" + aFruits);
//Loop over array
for (let i = 0; i < aFruits.length; i++) {
const element = aFruits[i];
console.log("item at position " + i + "------->" + element);

// Working with objects, they are like structures in ABAP, contains multiple
fileds of different type
var oEmployee = {
"empId" : 123456,
"empName" : "Sandeep",
"salary": 5000,
"currency": "USD"

};
console.log("A new object ------>" , oEmployee);

// Use jsonlint.com to validate json

console.log("Employee name is " + oEmployee.empName);


oEmployee.salary = 20000;
console.log("new Salary of Sandeep is " ,oEmployee.salary);

// loop over json


for (const key in oEmployee) {
console.log(oEmployee[key]);

// ComplexJson combination of array and object

var complexJson = {
empTab : [],
cities : [],
gender : {}

};

You might also like