Coding with Mohit
Ir al canal en Telegram
702
Suscriptores
-224 horas
-17 días
+530 días
Archivo de publicaciones
📜 Answer of this Question (click to see the question):
- The mongodb package is the official low-level Node.js driver that lets you connect to MongoDB and run database operations directly, offering flexibility but no built-in schemas, validation, or middleware. mongoose, on the other hand, is a higher-level ODM library built on top of that driver, providing schemas, models, validation, middleware, and utilities like population to enforce structure and streamline database interactions.
😁 Ek aur chhota sa question:
❓ What's the difference between mongodb & mongoose npm packages?
👇 Please comment your answer:
📜 Answer of this Question (click to see the question):
-
module.exports is from the CommonJS module system used historically in Node.js, while export / import belong to the modern ES Module (ESM) system standardized in ES6 and supported by both browsers and Node.js today.😁 Ek aur chhota sa question:
❓ What's the difference between:
function hello() {
console.log("Hello!");
}
module.exports = hello;
&
```js
export function hello() {
console.log("Hello!");
}
`
👇 Comment your answer please:const { log } = require("console");
const http = require("http");
const fs = require("fs");
http.createServer((req, res) => {
const filePath = req.url;
if (filePath === "/") {
const data = fs.readFileSync("staticFiles/index.html", "utf-8");
res.writeHead(200, {
"Content-Type": "text/html"
});
res.write(data);
res.end();
} else if (filePath === "/style.css") {
const data = fs.readFileSync("staticFiles/style.css", "utf-8");
res.writeHead(200, {
"Content-Type": "text/css"
});
res.write(data);
res.end();
} else if (filePath === "/script.js") {
const data = fs.readFileSync("staticFiles/script.js", "utf-8");
res.writeHead(200, {
"Content-Type": "application/javascript"
});
res.write(data);
res.end();
}
res.end();
}).listen(2346, () => {
log("Server is listening on port 2346!");
})
This is the way to serve Static Files using Backend (node.js) 😫 Isse achha to directly host karlo kahi 😶
Any Backend Developer comment if something is wrong 😐📜 Answer of this Question (click to see the question):
- IIFE (Immediately Invoked Function Expression) is a function which is called instantly on creation. Example:
(function () {
console.log("This is an IIFE!");
})();😁 Ek aur chhota sa question:
❓ What is IIFE in JavaScript? Give one example.
👇 Comment your answer (no GPT 🥲)
Itni achhi achhi cheeze bata raha, still neither any reaction nor any engagement 🙂💔
Kya chahiye? Only free Bots & Codes but Free Concepts......
📜 Answer of this Question (click to see the question):
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
const sum = numbers.reduce((acc, curr) => {
return acc + curr;
}, 0);
console.log(sum);
Explanation:
- reduce() method is a method used in Arrays which reduces an array to a single value. So here, we want a single value for this array which is the sum of the numbers. reduce() method takes 2 values which is accumulator and current where accumulator is result of every calculation performed with the current. So here, it's being added untill the last value which leads to the sum of the numbers.📜 Answer of the Question:
- A function in JavaScript is an independent block of reusable code. It can exist on its own and be called anywhere. Example:
function greet() {
console.log("Hello!");
}
- A method is a function that belongs to an object. Example:
const person = {
greet: function () {
console.log("Hello!");
}
};😅 Ek aur chhota sa question:
❓ Print the largest number.
const numbers = [2, 67, 0, 56, 23, 98, 11, 20, 65, 78, 97, 46];
👇 Comment your code please 😁😅 Ek aur chhota sa question:
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
❓ Find the sum of all numbers.
👇 Comment your code please 😁😅 Ek chhota sa question:
❓ What's the difference between Function & Method?
👇 Comment please 😁
"Waqt Aane Par Khulte Hai Saare Kirdar,
Pehli Nazar Me To Har Koi Wafadaar Lagta Hai"
