Javascript Node Js basic to Advance
1.09K subscribers
4 photos
1 video
2 files
39 links
Javascript Node Js group

@LogicB_Support
@BCA_MCA_BTECH
Download Telegram
Task:
Ek default asynchronous language se samajhaiye ki asynchronous language kis kis tarah se better hai


Explaination:
Default asynchronous language, jaise ki JavaScript, asynchronous programming mein kaafi accha hota hai kyunki yeh concurrently multiple tasks ko handle kar sakta hai bina kisi task ko rokne ke. 
Ismein ek task ke completion ke bina dusre tasks execute ho sakte hain, jisse efficiency badhti hai. Isse blocking nahi hota, jiska matlab hai ki ek task ke wait karne se dusre tasks ko block nahi kiya jaata, aur overall performance improve hoti hai.


Real world example:
Jaise ki JavaScript mein, agar ek website multiple resources ko load kar rahi hai jaise images, CSS files, aur data from a server, toh asynchronous nature allows simultaneous loading of these resources. 

Jab ek resource load ho raha hota hai, dusre resources simultaneously load ho sakte hain, isse website ke performance mein improvement hoti hai compared to synchronous loading jahan ek resource ke wait karte karte dusre resources ka loading process block ho jaata hai.


Code Example:
const axios = require('axios');

// Asynchronous GET request bhejna
axios.get('https://example.com')
.then(function (response) {
// Agar request successful hua
console.log(response.data);
})

// upar ka code execute hone se pahle ye excecute ho jayega kyuki JavaScript isko bhi uske sath simultaneously execute karega
console.log("Request bhej diya hai!");
Ab aap log apna khud ka Compiler bot bana sakte hain easily 🥳🥳🔥
Apne manpasand name aur username se

Create your own
By using @CloneCompiler_bot

See full details: Click Here
// Dimond pattern
require("jsshort")
input("Enter num: ")
.then((n)=>{
let str = '';

// top half
for (let i = 1; i <= n; i++) {
str = ' '.repeat(n - i);
str += '* '.repeat(i);
console.log(str);
}

// bottom half
for (let i = n - 1; i >= 1; i--) {
str = ' '.repeat(n - i);
str += '* '.repeat(i);
console.log(str);
}
})
// MorseCode encryption
class MorseCodeCipher {
  constructor() {
    // This is a JavaScript implementation of MorseCode Cipher
    this.morse_dict = {
      'A': '.-', 'B': '-...',
      'C': '-.-.', 'D': '-..', 'E': '.',
      'F': '..-.', 'G': '--.', 'H': '....',
      'I': '..', 'J': '.---', 'K': '-.-',
      'L': '.-..', 'M': '--', 'N': '-.',
      'O': '---', 'P': '.--.', 'Q': '--.-',
      'R': '.-.', 'S': '...', 'T': '-',
      'U': '..-', 'V': '...-', 'W': '.--',
      'X': '-..-', 'Y': '-.--', 'Z': '--..',
      '1': '.----', '2': '..---', '3': '...--',
      '4': '....-', '5': '.....', '6': '-....',
      '7': '--...', '8': '---..', '9': '----.',
      '0': '-----', ',': '--..--', '.': '.-.-.-',
      '?': '..--..', ' ': '/', '-': '-....-',
      '(': '-.--.', ')': '-.--.-'
    };

    this.reverse_morse = {};
    for (const [key, value] of Object.entries(this.morse_dict)) {
      this.reverse_morse[value] = key;
    }
  }

  encrypt(text) {
    let result = '';
    for (const ch of text.toUpperCase()) {
      result += this.morse_dict[ch] || ch;
      result += ' ';
    }
    return result.trim();
  }

  decrypt(text) {
    let result = '';
    for (const code of text.split(' ')) {
      result += this.reverse_morse[code] || code;
    }
    return result;
  }
}
(async ()=>{
const cipher = new MorseCodeCipher();
require("jsshort")
let work = await input("For decrypt 0 For encrypt enter any key: ")
if(work != '0'){
const plainText = await input("Enter text to encrypt: ")
const encryptedText = cipher.encrypt(plainText);
console.log('Encrypted Text:', encryptedText);
} else {
let enc = await input("Enter text to decrypt: ")
const decryptedText = cipher.decrypt(enc);
console.log('Decrypted Text:', decryptedText);
}
process.exit(0)
})()
// simplest function definition in js 😁

let e = e => +e
// Js Own event lib creation
class EventEmitter {
  funcs = [];
 
  constructor() {}
 
  on(mesType, callback) {
    this.funcs.push({ mesType, callback });
  }
 
  emit(mesType, obj) {
    this.funcs.forEach(funobj => {
      if (funobj.mesType == mesType) {
        funobj.callback(obj);
      }
    });
  }
}

/*
For use:
e = new EventEmitter();

e.on("mes", (mes)=> {
console.log("logic here")
})

e.emit("mes", {data: "mydata"})
*/
👍1
All video downloader js libraries:

Youtube video downloader
https://www.npmjs.com/package/ytdl-core

Insta video downloader
https://www.npmjs.com/package/snapsave-downloader-itj

Facebook video downloader
https://www.npmjs.com/package/fb-downloader-scrapper

Twitter video downloader
(If you have chrome then use update it in puppeteer-core)

https://github.com/JBLorincz/xvidrip
Or
Twitter video downloader
(Without puppeteer Old lib so needs some modification as twitter is now x.com)

https://www.npmjs.com/package/video-url-link?activeTab=code
👍1
// Js code to scrap phone numbers from string
str = "+911234567890 xyz abcd Xs bdtsk yts ki hrtsk 1212343409 djdb 23 yted l 1234567 Ynd yts"

console.log(str.match(/\+?\d{10,12}/g))
Javascript loops

for loop: It's used when you know the number of iterations. It consists of three parts: initialization, condition, and iteration statement.

for (let i = 0; i < 5; i++) {
console.log(i)
}


while loop: It executes a block of code while a specified condition is true.

let i = 0;
while (i < 5) {
console.log(i)
i++;
}


do...while loop: Similar to a while loop, but it always executes the block of code at least once, and then checks the condition.

let i = 0;
do {
console.log(i)
i++;
} while (i < 5);


for...in loop: Iterates over the enumerable properties of an object.

const obj = { a: 1, b: 2, c: 3 };
for (let prop in obj) {
// Code to be executed
console.log(prop + ': ' + obj[prop]);
}


for...of loop: Introduced in ES6, it iterates over iterable objects (arrays, strings, maps, sets, etc.).

const arr = [1, 2, 3];
for (let value of arr) {
console.log(value);
}


@nodejs_codes_pro
👍2
// Word count in string
require("jsshort").input("Enter string: ")

.then((Str)=>{
obj = {}
for(let x of Str)
obj[x] = (obj[x]||0) + 1

console.log(obj)
})
Array ( List ) functions of javascript 👇👇
// 1. push()
let arrPush = [1, 2, 3];
arrPush.push(4, 5);
console.log(arrPush); // Output: [1, 2, 3, 4, 5]
// 2. pop()
let arrPop = [1, 2, 3, 4, 5];
let popped = arrPop.pop();
console.log(popped); // Output: 5
console.log(arrPop); // Output: [1, 2, 3, 4]
// 3. shift()
let arrShift = [1, 2, 3, 4, 5];
let shifted = arrShift.shift();
console.log(shifted); // Output: 1
console.log(arrShift); // Output: [2, 3, 4, 5]
// 4. unshift()
let arrUnshift = [1, 2, 3];
arrUnshift.unshift(-3, -2, -1, 0);
console.log(arrUnshift); // Output: [-3, -2, -1, 0, 1, 2, 3]
// 5. splice()
let arrSplice = [1, 2, 3, 4, 5];
arrSplice.splice(2, 1, 'a', 'b');
console.log(arrSplice); // Output: [1, 2, 'a', 'b', 4, 5]
// 6. slice()
let arrSlice = [1, 2, 3, 4, 5];
let sliced = arrSlice.slice(1, 4);
console.log(sliced); // Output: [2, 3, 4]