A beginner-friendly RESTful Contact Management API built using Node.js, Express.js, MongoDB, and JWT Authentication. Designed for developers who want to learn backend fundamentals including user authentication, secure API practices, and CRUD operations using a clean MVC architecture.
🚀 Perfect for beginners transitioning from Frontend to Fullstack Development!
- 🔐 User Authentication (Register/Login) using hashed passwords and JWT
- 📁 CRUD Operations for managing contacts
- 🛡️ Protected Routes using JWT middleware
- 🗃️ MongoDB Integration via Mongoose
- 🧠 Clean and modular MVC Folder Structure
- 🧪 Built-in testing support using tools like Postman or Thunder Client
-
Clone the repository:
git clone <your-repo-url> cd Lecture_19_Project_4
-
Install dependencies:
npm install
-
Setup environment variables:
Create a
.envfile in the root folder and add the following:MONGO_URL=your_mongodb_connection_string JWT=your_jwt_secret_key PORT=5000 -
Run the server:
node server.js
Or using nodemon:
nodemon server.js
| Endpoint | Method | Description |
|---|---|---|
/api/user/register |
POST | Register a new user |
/api/user/login |
POST | Login and receive JWT token |
{
"name": "John",
"email": "john@example.com",
"password": "123456"
}| Endpoint | Method | Description |
|---|---|---|
/api/contact/new |
POST | Create new contact |
/api/contact/ |
GET | Get all contacts |
/api/contact/:id |
GET | Get a specific contact by ID |
/api/contact/:id |
PUT | Update a contact |
/api/contact/:id |
DELETE | Delete a contact |
/api/contact/userid/:id |
GET | Get all contacts for a specific user |
💡 Note: Use the
Authheader to pass your JWT token like this:
Auth: Bearer <your_token>
fetch('/api/user/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: 'John',
email: 'john@example.com',
password: '123456'
})
});Lecture_19_Project_4/
│
├── controllers/ # Business logic
├── models/ # Mongoose models
├── routes/ # API routes
├── middleware/ # JWT & error handlers
├── config/ # DB config
├── .env # Environment variables
├── server.js # App entry point
└── package.json
This project was built as part of my Node.js backend learning journey. Special thanks to my mentors, online communities, and resources that helped along the way.
Feel free to ⭐ star, 🛠️ fork, or 🔁 contribute!
Happy Learning & Coding!