This guide contains:
This README is specially prepared according to:
A closure is a function that remembers variables from its outer scope even after the outer function has finished execution.
function outer() {
let count = 0;
return function inner() {
count++;
console.log(count);
};
}
const counter = outer();
counter(); // 1
counter(); // 2
Closures are used in:
JavaScript moves declarations to the top before execution.
console.log(a);
var a = 10;
Internally:
var a;
console.log(a); // undefined
a = 10;
| == | === | | βββββ- | ββββββ- | | Loose comparison | Strict comparison | | Checks value | Checks value + type |
console.log(5 == "5"); // true
console.log(5 === "5"); // false
Node.js is single-threaded but handles asynchronous tasks using:
Call Stack β Web APIs β Callback Queue β Event Loop
console.log("Start");
setTimeout(() => {
console.log("Timeout");
}, 0);
console.log("End");
Output:
Start
End
Timeout
Virtual DOM is a lightweight copy of the real DOM.
React compares:
Then updates only changed elements.
Hooks allow functional components to use:
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
{count}
</button>
);
}
Used for:
useEffect(() => {
fetchData();
}, []);
| Dependency | Meaning |
|---|---|
| [] | Runs once |
| [count] | Runs when count changes |
| No array | Runs every render |
export default React.memo(Component);
Prevents unnecessary re-renders.
const value = useMemo(() => expensiveCalculation(), []);
Caches expensive calculations.
const handleClick = useCallback(() => {}, []);
Caches functions.
const Dashboard = React.lazy(() => import("./Dashboard"));
Loads component only when needed.
| Type | Meaning |
|---|---|
| CSR | Client-side rendering |
| SSR | Server-side rendering |
| SSG | Static site generation |
export async function getServerSideProps() {
return {
props: {}
};
}
Node.js is a JavaScript runtime built on Chrome V8 engine.
Used for:
Middleware runs between request and response.
app.use((req, res, next) => {
console.log("Middleware");
next();
});
Login β Generate Token β Send Token β Verify Token
const token = jwt.sign(
{ id: user._id },
SECRET_KEY,
{ expiresIn: "1d" }
);
jwt.verify(token, SECRET_KEY);
app.get("/users", getUsers);
app.post("/users", createUser);
app.put("/users/:id", updateUser);
app.delete("/users/:id", deleteUser);
| SQL | NoSQL |
|---|---|
| Tables | Documents |
| Structured | Flexible |
| Relations | Schema-less |
const userSchema = new mongoose.Schema({
name: String,
email: String
});
Indexes improve search speed.
userSchema.index({ email: 1 });
User.aggregate([
{
$match: {
age: { $gt: 18 }
}
}
]);
| Join | Meaning |
|---|---|
| INNER JOIN | Matching records |
| LEFT JOIN | All left records |
| RIGHT JOIN | All right records |
SELECT users.name, orders.total
FROM users
INNER JOIN orders
ON users.id = orders.user_id;
Redis is an in-memory database used for:
Without Redis:
Request β Database β Response
With Redis:
Request β Redis Cache β Fast Response
await redis.set("users", JSON.stringify(data));
Client
β
Load Balancer
β
API Server
β
Redis Cache
β
Database
| Monolith | Microservices |
|---|---|
| Single app | Multiple services |
| Easier initially | More scalable |
Docker packages application + dependencies into containers.
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]
| CI | CD |
|---|---|
| Continuous Integration | Continuous Deployment |
name: Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
function debounce(fn, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => {
fn(...args);
}, delay);
};
}
I already have practical experience working on production-level MERN applications, performance optimization, CI/CD deployment, and scalable backend systems. I can contribute quickly with minimal guidance.
Iβm looking for larger technical challenges, better growth opportunities, and an environment where I can improve my architecture and backend skills further.
Revise:
Instead say:
βI havenβt used it deeply yet, but I understand the basics.β
Your strongest points:
Main focus now:
Mithlesh Prasad Full Stack MERN Developer React.js | Node.js | MongoDB | DevOps | AWS | Docker
DSA Learning Hub is an interactive platform designed to help learners explore and master Data Structures and Algorithms (DSA). It provides examples, API integrations, and will soon include interactive visualizations for various topics such as arrays, strings, linked lists, stacks, graphs, and more.
root/
β
βββ index.html # Main HTML file for the website
βββ server.js # Express server for API endpoints
βββ README.md # Project documentation
βββ styles.css # (Optional) External stylesheet for custom styles
/infoGET{
"status": true,
"message": "JSON server run successful!",
"server": "Express"
}
/arrayGET{
"status": true,
"array": "Originally array 1,2,3,4,5,6 <br> Reversed array: 6,5,4,3,2,1"
}
git clone <repository-url>
cd dsa-learning-hub
npm install
node server.js
The server will start at http://localhost:8045.
index.html in a browser or serve it using a tool like Live Server.Contributions are welcome! Hereβs how you can help:
This project is licensed under the MIT License. Feel free to use, modify, and distribute it as you like.
///////////////////////////////////////////////////////////////////////////////////////////////////////////// π₯ Alright Mithlesh! Here is the COMPLETE Day-by-Day DevOps Plan (40 Days) β the most practical, industry-ready roadmap made specifically for you as a MERN developer.
π Save this. Follow this. You will become DevOps Engineer in 40 Days.
No theory bullshit. Only practical + real projects.
Learn:
ls, cd, pwd, mkdir, rmcat, touch, lesssudo, apt update, apt installchmod, chownps, kill, top, htopsystemctl start/stop/statusping, curl, wget, ss -tulpnShell scripting basics:
Write a script:
#!/bin/bash
echo "Server Time: $(date)"
.gitignoreDeploy a Node.js API on local Linux + push to GitHub.
π― Project Result: MERN backend deployed manually on AWS EC2 using NGINX + PM2
Write Dockerfile for Node.js app:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node","index.js"]
Run container:
docker build -t myapp .
docker run -p 3000:3000 myapp
Example:
services:
api:
build: .
ports:
- 3000:3000
depends_on:
- db
db:
image: mongo
ports:
- 27017:27017
π― Complete: Dockerize full MERN app + run on EC2 + push image to Docker Hub
Create .github/workflows/deploy.yml
Triggers on push:
name: Node CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
π― Complete: Fully automated CI/CD: On every push β Build Docker β Deploy to EC2
Create main.tf:
resource "aws_instance" "web" {
ami = "ami-12345"
instance_type = "t2.micro"
}
Use S3 + DynamoDB lock
Break infra into modules.
Build:
via one command:
terraform apply
π― Complete: MERN app + EC2 + IAM + S3 fully created through Terraform
π― Deploy a Production-grade MERN App:
This is 100% real DevOps project. Hereβs a clean complete list of Top 20 pattern questions in Node.js/JavaScript with comments for understanding. These are the most commonly asked in coding rounds and help build loop logic strongly.
let n = 5;
for (let i = 1; i <= n; i++) { // Controls rows
let row = "";
for (let j = 1; j <= n; j++) { // Controls columns
row += "* ";
}
console.log(row);
}
Output:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
// Print stars equal to row number
for (let j = 1; j <= i; j++) {
row += "* ";
}
console.log(row);
}
Output:
*
* *
* * *
* * * *
* * * * *
let n = 5;
for (let i = n; i >= 1; i--) {
let row = "";
// Print decreasing stars
for (let j = 1; j <= i; j++) {
row += "* ";
}
console.log(row);
}
Output:
* * * * *
* * * *
* * *
* *
*
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
// Left spaces
for (let s = 1; s <= n - i; s++) {
row += " ";
}
// Stars
for (let j = 1; j <= i; j++) {
row += "* ";
}
console.log(row);
}
Output:
*
* *
* * *
* * * *
* * * * *
let n = 5;
for (let i = n; i >= 1; i--) {
let row = "";
// Leading spaces
for (let s = 1; s <= n - i; s++) {
row += " ";
}
// Stars
for (let j = 1; j <= i; j++) {
row += "* ";
}
console.log(row);
}
let n = 4;
// Upper part
for (let i = 1; i <= n; i++) {
let row = "";
row += " ".repeat(n - i);
row += "* ".repeat(i);
console.log(row);
}
// Lower part
for (let i = n - 1; i >= 1; i--) {
let row = "";
row += " ".repeat(n - i);
row += "* ".repeat(i);
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
for (let j = 1; j <= n; j++) {
// Border stars only
if (i === 1 || i === n || j === 1 || j === n) {
row += "* ";
} else {
row += " ";
}
}
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
for (let j = 1; j <= i; j++) {
// First, last and bottom stars
if (j === 1 || j === i || i === n) {
row += "* ";
} else {
row += " ";
}
}
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
// Print numbers from 1 to row number
for (let j = 1; j <= i; j++) {
row += j + " ";
}
console.log(row);
}
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
let n = 5;
for (let i = n; i >= 1; i--) {
let row = "";
for (let j = 1; j <= i; j++) {
row += j + " ";
}
console.log(row);
}
let n = 5;
let num = 1;
for (let i = 1; i <= n; i++) {
let row = "";
for (let j = 1; j <= i; j++) {
row += num + " ";
num++; // Increment every time
}
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
for (let j = 1; j <= i; j++) {
// Alternate between 0 and 1
row += (i + j) % 2 + " ";
}
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
// Forward numbers
for (let j = 1; j <= i; j++) {
row += j;
}
// Backward numbers
for (let j = i - 1; j >= 1; j--) {
row += j;
}
console.log(row);
}
let n = 5;
for (let i = 0; i < n; i++) {
let row = "";
let num = 1;
for (let j = 0; j <= i; j++) {
row += num + " ";
// Formula
num = num * (i - j) / (j + 1);
}
console.log(row);
}
let n = 4;
// Upper
for (let i = 1; i <= n; i++) {
let row = "";
row += "* ".repeat(i);
row += " ".repeat(2 * (n - i));
row += "* ".repeat(i);
console.log(row);
}
// Lower
for (let i = n; i >= 1; i--) {
let row = "";
row += "* ".repeat(i);
row += " ".repeat(2 * (n - i));
row += "* ".repeat(i);
console.log(row);
}
let n = 5;
for (let i = 0; i < n; i++) {
let row = "";
for (let j = 0; j < n; j++) {
// Diagonal stars
if (i === j || i + j === n - 1) {
row += "* ";
} else {
row += " ";
}
}
console.log(row);
}
let n = 5;
let mid = Math.floor(n / 2);
for (let i = 0; i < n; i++) {
let row = "";
for (let j = 0; j < n; j++) {
// Middle row or column
if (i === mid || j === mid) {
row += "* ";
} else {
row += " ";
}
}
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
row += " ".repeat(n - i);
for (let j = 1; j <= i; j++) {
row += i + " ";
}
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
row += " ".repeat(n - i);
// Descending
for (let j = i; j >= 1; j--) {
row += j;
}
// Ascending
for (let j = 2; j <= i; j++) {
row += j;
}
console.log(row);
}
let n = 5;
for (let i = 1; i <= n; i++) {
let row = "";
for (let j = 0; j < i; j++) {
row += String.fromCharCode(65 + j) + " ";
}
console.log(row);
}
Output:
A
A B
A B C
A B C D
A B C D E
These 20 cover almost all interview loop patterns in Node.js/JavaScript. Once you understand these, advanced patterns become much easier. Here are Top 20 Array + String DSA questions in JavaScript/Node.js (very common in interviews), with code + comments + output.
```javascript id=βa1x93dβ let arr = [1, 2, 3, 4, 5];
// reverse() modifies original array let reversed = arr.reverse();
console.log(reversed);
Output:
```text id="r81kd2"
[5,4,3,2,1]
```javascript id=βd82ks1β let arr = [10, 50, 20, 80, 30];
let max = arr[0];
for (let i = 1; i < arr.length; i++) { // Update max if bigger number found if (arr[i] > max) { max = arr[i]; } }
console.log(max);
Output:
```text id="m82ld0"
80
```javascript id=βs7d8k2β let arr = [10, 50, 20, 80, 30];
let min = arr[0];
for (let i = 1; i < arr.length; i++) { if (arr[i] < min) { min = arr[i]; } }
console.log(min);
Output:
```text id="n1j8k3"
10
```javascript id=βp8q9s1β let arr = [1, 2, 3, 4, 5]; let sum = 0;
for (let num of arr) { sum += num; }
console.log(sum);
Output:
```text id="w7c8d2"
15
```javascript id=βe4k2d8β let arr = [1, 2, 2, 3, 4, 4];
// Set stores unique values let unique = [β¦new Set(arr)];
console.log(unique);
Output:
```text id="f3d8s1"
[1,2,3,4]
```javascript id=βk2m9d1β let arr = [10, 50, 20, 80, 30];
arr.sort((a, b) => b - a);
// Second largest after sorting console.log(arr[1]);
Output:
```text id="l8s3k2"
50
```javascript id=βu8d1k3β let arr = [1, 2, 3, 4, 5]; let sorted = true;
for (let i = 0; i < arr.length - 1; i++) { if (arr[i] > arr[i + 1]) { sorted = false; break; } }
console.log(sorted);
Output:
```text id="g2m9s4"
true
```javascript id=βb3k7m2β let arr = [1, 2, 3, 4, 5];
// Remove first element let first = arr.shift();
// Add at end arr.push(first);
console.log(arr);
Output:
```text id="p4s8d1"
[2,3,4,5,1]
```javascript id=βm9s2k1β let arr = [1, 2, 4, 5]; let n = 5;
// Sum formula let total = (n * (n + 1)) / 2;
let sum = arr.reduce((a, b) => a + b, 0);
console.log(total - sum);
Output:
```text id="v7d8m3"
3
```javascript id=βq2d7m9β let arr1 = [1, 2]; let arr2 = [3, 4];
// Merge using spread let merged = [β¦arr1, β¦arr2];
console.log(merged);
Output:
```text id="t8s4m1"
[1,2,3,4]
```javascript id=βr8m3k2β let str = βhelloβ;
// Split β reverse β join let reversed = str.split(ββ).reverse().join(ββ);
console.log(reversed);
Output:
```text id="j2k9d1"
olleh
```javascript id=βw2m8d1β let str = βmadamβ;
let reversed = str.split(ββ).reverse().join(ββ);
// Compare original and reversed console.log(str === reversed);
Output:
```text id="s7d9k2"
true
```javascript id=βf9k3d1β let str = βjavascriptβ; let count = 0;
for (let ch of str) { if (βaeiouβ.includes(ch)) { count++; } }
console.log(count);
Output:
```text id="x8m2d1"
3
```javascript id=βn3d8k1β let str = βprogrammingβ; let map = {};
for (let ch of str) { map[ch] = (map[ch] || 0) + 1; }
for (let key in map) { if (map[key] > 1) { console.log(key); } }
Output:
```text id="c9k2m1"
r
g
m
```javascript id=βt2m8d1β let str = βswissβ; let map = {};
for (let ch of str) { map[ch] = (map[ch] || 0) + 1; }
for (let ch of str) { if (map[ch] === 1) { console.log(ch); break; } }
Output:
```text id="h8d3m1"
w
```javascript id=βy3k8d1β let str1 = βlistenβ; let str2 = βsilentβ;
// Sort both and compare let result = str1.split(ββ).sort().join(ββ) === str2.split(ββ).sort().join(ββ);
console.log(result);
Output:
```text id="m4d9k2"
true
```javascript id=βu2d8k1β let str = βhelloβ; let count = {};
for (let ch of str) { count[ch] = (count[ch] || 0) + 1; }
console.log(count);
Output:
```text id="q7m2d1"
{ h:1, e:1, l:2, o:1 }
```javascript id=βo8k2d1β let str = βhello worldβ;
// Replace spaces with empty let result = str.replace(/\s/g, ββ);
console.log(result);
Output:
```text id="p2m8d1"
helloworld
```javascript id=βl8d2m1β let str = βI love javascript programmingβ;
let words = str.split(β β); let longest = ββ;
for (let word of words) { if (word.length > longest.length) { longest = word; } }
console.log(longest);
Output:
```text id="n8k2d1"
programming
```javascript id=βz2m8d1β let str = βhello worldβ;
let result = str .split(β β) .map(word => word.charAt(0).toUpperCase() + word.slice(1) ) .join(β β);
console.log(result);
Output:
```text id="v2d9m1"
Hello World
Focus on these first:
β Reverse Array β Max/Min β Remove Duplicates β Missing Number β Palindrome β Anagram β First Non-Repeating Character β Duplicate Characters β Longest Word β Character Count
////////////////////////////////////////////////////////////////////////////// β
Built with β€οΈ by Mithlesh Prasad.