Site icon Cody Paste

NODE.JS BASIC SETUP – (BEGINNER)

1️⃣ Node.js & npm Installation Check

Command Prompt / Terminal:

node -v
npm -v

Expected Output:

Node : v20.x.x
NPM : 10.x.x

👉 Agar version aa raha hai → Node & npm installed ✅


2️⃣ Project Folder Location

Node project kahin bhi ho sakta hai (htdocs zaroori nahi)

Example:

E:\node-project\node-shop

Node ko folder location se koi farak nahi padta.


3️⃣ Project Open in VS Code

E:\node-project\node-shop
Ctrl +

Terminal path check:

PS E:\node-project\node-shop>

4️⃣ Node Project Initialize

npm init -y

👉 Ye package.json banata hai
(CI4 ke composer.json jaisa)


5️⃣ Required Packages Install

npm install express mysql2 dotenv cors
npm install -D nodemon

Packages use:


6️⃣ Folder Structure (CI4 style)

node-shop/
├─ src/
├─ controllers/ Logic (CI4 Controllers)
├─ routes/ Routes (CI4 Routes.php)
├─ db/ Database config
└─ app.js Entry point
├─ .env
├─ package.json
└─ node_modules/

7️⃣ app.js (First Node Server)

📄 src/app.js

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

app.use(express.json());

app.get('/', (req, res) => {
res.send('Node server chal raha hai bhai 😎');
});

const PORT = 3000;
app.listen(PORT, () => {
console.log(

Server running on http://localhost:${PORT}`);
});

8️⃣ package.json Scripts Setup

📄 package.json me scripts section:

"scripts": {
"start": "node src/app.js",
"dev": "nodemon src/app.js"
}

👉 npm run dev = development mode
👉 npm start = normal mode


9️⃣ Server Run Command

npm run dev

Expected Terminal Output:

Server running on http://localhost:3000

🔟 Browser Test

Open browser:

http://localhost:3000

Output:

Node server chal raha hai bhai 😎

👉 Matlab:


🧠 CI4 → Node Mindset Mapping (Quick)

CI4 Node
Apache + index.php Node server + app.js
Routes.php routes/*.js
Controllers controllers/*.js
php spark serve npm run dev

🎯 Current Status

✔ Node installed
✔ npm working
✔ Project setup
✔ Express server running


🔜 NEXT TOPIC (Future Notes)

Exit mobile version