A RESTful Contact Management API built with Node.js, Express, MongoDB, and JWT authentication.
Project Status:
This project is a backend API created while learning the fundamentals of Express.js development. It demonstrates how to build a secure REST API with user authentication, CRUD operations, middleware, and MongoDB integration.
- User registration and login
- JWT authentication
- Password hashing with bcrypt
- Protected API routes
- Full CRUD operations for contacts
- MongoDB database integration
- Centralized error handling
- Environment variable configuration
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT (JSON Web Tokens)
- bcrypt
- dotenv
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/users/register |
Register a new user |
| POST | /api/users/login |
Authenticate a user |
| GET | /api/users/current |
Get the current authenticated user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/contacts |
Get all contacts |
| GET | /api/contacts/:id |
Get a single contact |
| POST | /api/contacts |
Create a contact |
| PUT | /api/contacts/:id |
Update a contact |
| DELETE | /api/contacts/:id |
Delete a contact |
mycontacts-backend/
├── config/
├── controllers/
├── middleware/
├── models/
├── routes/
├── server.js
└── package.json
Install dependencies:
npm installCreate a .env file:
PORT=5000
CONNECTION_STRING=<your_mongodb_connection_string>
ACCESS_TOKEN_SECRET=<your_jwt_secret>Start the development server:
npm run devOr run normally:
npm start- REST API design
- Express routing
- MVC architecture
- Authentication with JWT
- Password hashing
- Middleware
- MongoDB and Mongoose
- Environment variables
- Error handling
| Component | Status |
|---|---|
| Authentication | Complete |
| JWT Authorization | Complete |
| Contact CRUD API | Complete |
| MongoDB Integration | Complete |
| Error Handling | Complete |
This repository serves as a learning project for building secure REST APIs with Node.js and Express. It provides a solid foundation for developing larger backend applications that require authentication, database integration, and CRUD functionality.