Skip to content

MoARABY/contact-manager-app-nodeJS

Repository files navigation

Contact Management System - Backend

This repository contains the backend code for a contact management system built using Node.js, Express, and MongoDB.

Features

CRUD operations for managing contacts User authentication and authorization using JWT and bcrypt Middleware for request validation and error handling Separation of concerns using controllers, models, and routes

Technologies Used

  • Node.js
  • Express.js
  • MongoDB
  • JSON Web Tokens (JWT) for authentication
  • bcrypt for password hashing
  • dotenv
  • express-async-handler
  • mongoose
  • nodemon

Setup Instructions

Install dependencies:

  • > bash
  • > cd contact-management-backend
  • > npm install
  • > Create a .env file in the root directory.
  • > Add the following environment variables:
  • >> makefile
  • >> PORT=3000
  • >> MONGODB_URI=your-mongodb-connection-string
  • >> JWT_SECRET=your-jwt-secret
Configure environment variables:
  • > Start the server:
  • >> bash
  • >> npm start

API Endpoints

  • POST /api/users/register: Register a new user.
  • POST /api/users/login: Login with email and password to get JWT token.
  • GET /api/contacts: Get all contacts.
  • POST /api/contacts: Create a new contact.
  • GET /api/contacts/:id: Get a contact by ID.
  • PUT /api/contacts/:id: Update a contact by ID.

Folder Structure

  • middlewares/: Custom middleware functions.
  • controllers/: Request handlers for each route.
  • models/: Mongoose schemas and models.
  • routes/: Express routes for different endpoints.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

This project is licensed under the MIT License.