https://github.com/aaringuleria/contactmanagementapp
It covers different Nodejs, Express, MongoDB & JWT Topics and implementation in one single project. It showcases the Express concepts and their use in practical project.
https://github.com/aaringuleria/contactmanagementapp
expressjs jwt mongodb node-js
Last synced: 3 months ago
JSON representation
It covers different Nodejs, Express, MongoDB & JWT Topics and implementation in one single project. It showcases the Express concepts and their use in practical project.
- Host: GitHub
- URL: https://github.com/aaringuleria/contactmanagementapp
- Owner: AarinGuleria
- Created: 2024-08-12T06:53:54.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-20T10:20:05.000Z (over 1 year ago)
- Last Synced: 2025-05-20T05:08:47.351Z (about 1 year ago)
- Topics: expressjs, jwt, mongodb, node-js
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme
Awesome Lists containing this project
README
# 📞 MyContacts Backend API
Welcome to the **MyContacts Backend API**! This production-ready Node.js/Express.js application provides a robust backend system for managing contacts with secure authentication and MongoDB integration.
## ✨ Features
- 🔐 Secure JWT Authentication & Authorization
- 📝 Complete CRUD Operations for Contacts Management
- 🎯 Request Validation using Express Validator
- 🔄 Global Error Handling & Custom Error Responses
- 📦 MongoDB & Mongoose Integration
- 🛡️ Express Middleware for Route Protection
- 🔒 Password Hashing with Bcrypt
- 📊 User-specific Contact Management
- ⚡ Async/Await Implementation with Express-Async-Handler
## 🚀 Getting Started
### Prerequisites
- Node.js (v14 or higher)
- MongoDB (local or Atlas URI)
- npm/yarn package manager
### Installation & Setup
1. Clone the repository:
```bash
git clone https://github.com/yourusername/mycontacts-backend.git
```
2. Install dependencies:
```bash
cd mycontacts-backend
npm install
```
3. Create a `.env` file in the root directory:
```env
PORT=5001
CONNECTION_STRING=your_mongodb_uri
ACCESS_TOKEN_SECRET=your_secret_key
```
### 🏃♂️ Running the Application
1. Start the production server:
```bash
npm start
```
2. For development with nodemon:
```bash
npm run dev
```
## 📚 API Documentation
### Authentication Endpoints
- POST `/api/users/register` - Register a new user
- Required fields: username, email, password
- Returns: User object with JWT token
- POST `/api/users/login` - Login user
- Required fields: email, password
- Returns: JWT token & user info
- GET `/api/users/current` - Get current user info (Protected Route)
- Requires: Valid JWT token in Authorization header
### Contacts Endpoints (Protected Routes)
- GET `/api/contacts` - Get all contacts for logged in user
- Returns: Array of contact objects
- POST `/api/contacts` - Create new contact
- Required fields: name, email, phone
- Optional fields: description
- GET `/api/contacts/:id` - Get contact by ID
- Returns: Single contact object
- PUT `/api/contacts/:id` - Update contact
- Updateable fields: name, email, phone, description
- DELETE `/api/contacts/:id` - Delete contact
- Returns: Success message
## 🛠️ Tech Stack
- Express.js - Web framework
- MongoDB & Mongoose - Database & ODM
- JWT - Authentication & Authorization
- Express-Async-Handler - Async operations handling
- Express Validator - Input validation
- Bcrypt - Password hashing
- Dotenv - Environment variables management
- Nodemon - Development server
## 🔐 Security Features
- Password Hashing
- JWT Token Authentication
- Protected Routes
- Input Sanitization
- User-specific Data Access
- Error Handling
## 📝 License
This project is licensed under the MIT License. Feel free to use, modify, and distribute as per the license terms.