Live Updates
Initializing JARVIS Data Stream... Synchronizing Feeds...
Important

Anti-Fraud Alert: This portal does not charge any service fees from candidates. All services provided here are 100% Free of Cost. Please stay cautious of unauthorized individuals asking for money.

BASIC NODE JS

Node.js – Complete Core Notes

🌐 Node.js – Complete Basic Notes

Architecture, Core Modules, HTTP Server, NPM Packages aur Express.js ka comprehensive visual guide.

1️⃣ Node.js Kya Hai?

Definition: Node.js ek JavaScript runtime environment hai jo JS code ko browser ke bahar direct computer / server par run karne ki permission deta hai.

Frontend vs Backend: Browser me JS sirf buttons aur UI effects manage karti hai. Node.js ke sath wahi JavaScript database connect karne, files read/write karne aur backend APIs banane ka kaam karti hai.
  • Backend Development: APIs, database operations aur user authentication ke liye use hota hai.
  • Google V8 Engine: Yeh wahi ultra-fast C++ engine use karta hai jo Google Chrome browser me laga hai.
  • Scalable & Fast: High network traffic ko bina crash hue handle karne me capable hai.

2️⃣ Node.js Ke Core Features

  • Asynchronous & Non-Blocking: Ek task (jaise file read karna) complete hone tak baaki requests block nahi hoti, sab parallel process hota hai.
  • Single-Threaded Event Loop: Light-weight memory usage ke sath hazaron requests ek sath handle karta hai.
  • NPM (Node Package Manager): Lakhon ready-made open-source libraries ka store.
  • Cross-Platform: Windows, Mac aur Linux sabhi par same code chalta hai.

3️⃣ Node.js Installation & Setup

1. Official website nodejs.org se LTS version download karein.

2. Terminal / Command Prompt me version verify karein:

node -v
npm -v

4️⃣ First Node.js Program

Ek file banayein app.js aur usme yeh code likhein:

console.log("Hello Node.js Backend!");

Terminal me run karne ke liye likhein:

node app.js
Live Server Output Simulation
$ Click the button above to simulate running terminal code...

5️⃣ Modules (Core Modules)

Definition: Node.js me pehle se bani hui libraries hoti hain jinhe bina install kiye direct require() karke use kiya ja sakta hai.

Module Name Syntax Preview Purpose / Kaam
fs (File System) const fs = require('fs'); Files create, read, update aur delete karne ke liye.
http const http = require('http'); Node.js me custom web server banane ke liye.
path const path = require('path'); File directories aur folders ke path manage karne ke liye.
// File read karne ka simple example
const fs = require('fs');

fs.writeFileSync("test.txt", "Backend course notes.");
const data = fs.readFileSync("test.txt", "utf-8");
console.log(data); // "Backend course notes."

6️⃣ Creating a Simple Web Server

Bina kisi third-party tool ke built-in http module se banaya gaya basic server:

const http = require('http');

// Server Create karna
const server = http.createServer((req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.write("Hello World from Node Server!");
    res.end();
});

// Port 3000 par listen karna
server.listen(3000, () => {
    console.log("Server running at http://localhost:3000/");
});
  • req (Request): User kya request bhej raha hai (URL, Data).
  • res (Response): Server user ko kya wapas bhej raha hai (HTML, Text, JSON).

7️⃣ NPM (Node Package Manager)

Jab hume project me external packages ya libraries install karni hoti hain:

// 1. Naya project initialize karna (package.json create karta hai)
npm init -y

// 2. Koi bhi package install karna
npm install express
npm install dotenv
Popular Package Use Case
express Fast aur lightweight web APIs banane ke liye.
mongoose MongoDB database ke sath data connect karne ke liye.
dotenv Passwords aur secret API keys ko secure rakhne ke liye.

8️⃣ Express.js (Node.js Ka Popular Framework)

Native http module me code bohot lamba ho jata hai. Express.js se routes aur APIs banana bohot aasan ho jata hai.

const express = require('express');
const app = express();

// Home Page Route
app.get('/', (req, res) => {
    res.send("Welcome to Express Backend Server!");
});

// API Endpoint Route
app.get('/api/users', (req, res) => {
    res.json([
        { id: 1, name: "Rahul" },
        { id: 2, name: "Priya" }
    ]);
});

// Server Start
app.listen(3000, () => {
    console.log("Express active on http://localhost:3000");
});
Live Express API Route Simulation
// Click the button to get mock API JSON response...

🔹 Quick Development Tips

  • Auto Restart: Har baar code change karne par server manually restart na karna pade, iske liye npm install -g nodemon ya native node --watch app.js use karein.
  • Environment Variables: Production passwords ko kabhi direct code me na likhein; hamesha .env file me rakhein.
  • Status Codes: Hamesha sahi HTTP status codes return karein (e.g. 200 for Success, 404 for Not Found, 500 for Server Error).