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

  • VS Code โ†’ File โ†’ Open Folder

  • Select:

E:\node-project\node-shop
  • Terminal open:

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:

  • express โ†’ framework

  • mysql2 โ†’ MySQL connection

  • dotenv โ†’ env config

  • cors โ†’ API access

  • nodemon โ†’ auto server restart (dev)


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:

  • Node working โœ…

  • Express working โœ…

  • Setup complete โœ…


๐Ÿง  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)

  • MySQL connection (XAMPP)

  • CRUD (GET / POST / PUT / DELETE)

  • Admin panel + User website

  • JWT login

  • E-commerce flow

Leave a Reply

Your email address will not be published. Required fields are marked *