Install Node.js
First, make sure Node.js is installed.
Check:
👉 If not installed, download from nodejs.org (LTS version).
2️⃣ Create a new project
Initialize npm:
3️⃣ Install Express.js
4️⃣ Create index.js
Create a file named index.js and add this code:
5️⃣ Run the server
You’ll see:
6️⃣ Open in browser
Go to 👉 http://localhost:3000
🎉 Output:
(Optional) Auto-restart with nodemon
For development:
Go to 👉 https://www.npmjs.com/
Search nodemon pakage
Update package.json:
Run:
🔹 What is Routing in Express?
Routing decides how your app responds to a client request (URL + HTTP method).
👉 Syntax:
Example:
1️⃣ Basic Routes
2️⃣ Route Parameters (Dynamic Routes)
Used when data comes from URL.
URL:
Output:
Multiple params:
3️⃣ Query Parameters
Used for filters, pagination, search.
URL:
4️⃣ Route Handlers (Multiple Callbacks)
5️⃣ Express Router (Best Practice)
Use Router to organize routes (like modules in Drupal).
📁 Folder structure
routes/users.js
app.js
URLs:
6️⃣ Route Grouping
7️⃣ Middleware in Routing
8️⃣ 404 Route Handling
Always keep at the bottom 👇
9️⃣ REST API Example (Real World)

No comments:
Post a Comment
If you have any problem please let me know.