A simple Express.js backend project demonstrating how to use route parameters in an API.
This project shows how dynamic route parameters work in Express.js using the following pattern:
/users/:id
The id is captured from the URL and accessed using:
req.params.id
- Node.js
- Express.js
express-project-03-route-params-api
│
├─ src
│ ├─ controllers
│ │ └─ user.controller.js
│ │
│ └─ routes
│ └─ user.routes.js
│
├─ index.js
├─ package.json
└─ .gitignore
Clone the repository
git clone https://github.com/a2rp/express-project-03-route-params-api.git
cd express-project-03-route-params-apiInstall dependencies
npm installnode index.jsServer runs at:
http://localhost:3000
GET /users/:id
Example:
http://localhost:3000/users/25
Response:
{
"id": "25",
"name": "User 25",
"message": "User data fetched successfully for id 25"
}This project demonstrates:
- Express route parameters
- Dynamic API routes
- Controllers and route separation
- Basic backend architecture
Ashish Ranjan
Follow me:
- GitHub: https://github.com/a2rp
- Portfolio: https://www.ashishranjan.net
- LinkedIn: https://www.linkedin.com/in/aashishranjan
- Facebook: https://www.facebook.com/theash.ashish/
