Wednesday, 9 February 2022

Nodejs - ECMA Concept

ECMA Concept

-> 'let ' is an scope varible it can't be use as globle varible

-> if we'r using 'var' in place of let it will re-assign last defined value (means

    var a = 30

    var a = 30

    console.log("value of a is:"+a)

OUTPUT-

        value of a is = 30

)

if we are using 'let' inplace of var then it look like

let a=40;

let a=30;

OUTPUT

SyntaxError: Identifier 'a' has already been declared

    at wrapSafe (internal/modules/cjs/loader.js:1001:16)

    at Module._compile (internal/modules/cjs/loader.js:1049:27)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

    at Module.load (internal/modules/cjs/loader.js:950:32)

    at Function.Module._load (internal/modules/cjs/loader.js:790:12)

    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)

    at internal/main/run_main_module.js:17:47 


if we using scope varible

let a=30;


function esma_example(){
    let a = 40;
    console.log("value of a under function :"+a);
}

esma_example()
console.log("value of a:"+a);


output-

value of a under function :40

value of a:30


Nodejs- module exports

module exports

->it will help to get/fetch one module data into another module

main.js 

var name = "Kamal"
var person = function(a,b){
    var c = a+b
    console.log("sum of "+ a +" and "+ b +" is "+ c)
}

person(5,5);

module.exports.exp_example = name;


global_object.js

var main = require("./main")
console.log(__dirname)
console.log(__filename)
console.log(main.exp_example)


OUTPUT-

K:\NodeJs\Node Basics\chapter-1

K:\NodeJs\Node Basics\chapter-1\globalObject.js

Kamal

Nodejs - Global Objects

 Global Objects

-> We have two js files for accessing main.js objects we are using this functions in object.js

1)main.js

var person = function(a,b){
    var c = a+b
    console.log("sum of "+ a +" and "+ b +" is "+ c)
}

person(5,5);

2)global_objects.js

var main = require("./mian")
console.log(__dirname)
console.log(__filename)


output
sum of 5 and 5 is 10 K:\NodeJs\Node Basics\chapter-1 K:\NodeJs\Node Basics\chapter-1\globalObject.js




Nodejs - Arrow Functions

Arrorw Functions :
    
        -> Its a shortest way to define functions.

             EXAMPLE:    
            
            Without Parameter

                    var kamal =()=>{console.log("Its a arrow functions")}
                   
                     kamal()            ///call function

            With Parameter

                    var kamal =(a)=>{console.log("value of a is :"+a)}
                    
                    kamal(5)          ///call function

            With Multiple Parameter

                    var kamal =(a,b)=>{
                                
                    var  c=a+b
                    console.log("value of c is :"+c)}
                    
                    kamal(5,5)          ///call function

OUTPUT- value of c is :10

Nodejs - Anonymous Functions

 Anonymous Functions

    -> define variable then function

    Ex.-        !) Without parameter.... 

                     ver kamal = function(){

                        console.log("Its a anontmous function");

                    }

                    kamal()              ///call functions


                !!) With parameter...

                    var kamal = funtion(a,b){

                     var c = a+b

                    console.log("The value of  c is : "+c)

                     }


                    kamal(5,5)          //call functions


OUTPUT -  The value of  c is :10

NOTE: There is no name infront of function thats why its a anonymous function.



Thursday, 2 December 2021

NodeJs - Node Http & Query String

Basic Conecpts For Creating server and response code

Its a inbuilt modul with help of this module we can perform meny operationsIt Handle - Request & Response beacause it is a Hypertext Text Transfer Protocol(get request from user and give response to server)

1) For creating server we need Http module..

2) Url Handling : For Handlng Url we can use

var http = require('http');  --> inbuild module it access via direct requre method can access

var server = http.createServer(function(req , res){       ///create server

//Request Status , Content Type

server.writeHead(200,{"content-type":"text/plain"})

var url = req.url;                 //Url Handling

res.write(url)

res.end('Response End')     //print message

}) .listen(3000);


Note : Query String = Send Variable in browser with url

Url Handling

var http = require('http');  --> inbuild module it access via dirct method

var url = require('url');             //Handling Querystring

var server = http.createServer(function(req , res){       ///create server

server.writeHead(200,{"content-type":"text/plain"})

var result = url.parse(www.google.com?id=10, true).query;

res.write(res.name);   //things whinch want to get like name


}) .listen(3000);



Run-> localhost://300

Monday, 22 November 2021

Kotlin - Functions

 function with two Int parameters and Int return type.

sum of 3 and 5 is 8

A function body can be an expression. Its return type is inferred.

sum of 19 and 23 is 42

Kotlin - Observer

 Rxjava -  Observer - Based on data view willl render (react) karega. trotling -> making stream for execution (Means clicks event fire kr...