Skip to content

PranavThorat1432/Contact-API-using-NodeJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📞 Contact API with Full Authentication – Node.js, Express & MongoDB

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!


🏅 Badges

Node.js Express.js MongoDB JWT


✨ Features

  • 🔐 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

📦 Installation & Setup

🧰 Prerequisites

🚀 Steps

  1. Clone the repository:

    git clone <your-repo-url>
    cd Lecture_19_Project_4
    
    
  2. Install dependencies:

    npm install
  3. Setup environment variables:

    Create a .env file in the root folder and add the following:

    MONGO_URL=your_mongodb_connection_string
    JWT=your_jwt_secret_key
    PORT=5000
    
  4. Run the server:

    node server.js

    Or using nodemon:

    nodemon server.js

📚 API Endpoints

👤 User Authentication

Endpoint Method Description
/api/user/register POST Register a new user
/api/user/login POST Login and receive JWT token

🔐 Register Payload

{
  "name": "John",
  "email": "john@example.com",
  "password": "123456"
}

📇 Contacts (Requires JWT Auth)

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 Auth header to pass your JWT token like this:

Auth: Bearer <your_token>

🧪 Example Request (JavaScript fetch)

fetch('/api/user/register', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    name: 'John',
    email: 'john@example.com',
    password: '123456'
  })
});

📁 Project Structure (MVC)

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

🙌 Credits

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!


📣 Connect with Me

Happy Learning & Coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors