A RESTful API for managing contacts with user authentication built using Node.js, Express, and MongoDB.
API is deployed at: https://contacts-version-api-2.onrender.com
- User authentication with JWT
- CRUD operations for contacts
- Input validation
- Error handling
- MongoDB database integration
- Environment configuration
- Node.js
- Express.js
- MongoDB
- JWT Authentication
- Express-Async-Handler
- Bcrypt
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/users/register |
Register new user |
| POST | /api/users/login |
Login user |
| GET | /api/users/current |
Get current user info |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/contacts |
Get all contacts |
| POST | /api/contacts |
Create new contact |
| GET | /api/contacts/:id |
Get contact by ID |
| PUT | /api/contacts/:id |
Update contact |
| DELETE | /api/contacts/:id |
Delete contact |
- Clone the repository:
git clone https://github.com/Karunya-B/Contacts-version-api.git- Install dependencies:
cd Contacts-version-api
npm install- Create
.envfile:
PORT=5000
MONGODB_URI=your_mongodb_connection_string
ACCESS_TOKEN_SECRET=your_jwt_secret- Start the server:
# Development
npm run dev
# Production
npm startAll contact routes require JWT token in Authorization header:
Authorization: Bearer your_jwt_tokencurl -X POST https://contacts-api-mk9f.onrender.com/api/users/register \
-H "Content-Type: application/json" \
-d '{"username":"test","email":"test@test.com","password":"password123"}'curl -X POST https://contacts-api-mk9f.onrender.com/api/contacts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_jwt_token" \
-d '{"name":"John Doe","email":"john@example.com","phone":"1234567890"}'The API uses consistent error response format:
{
"title": "Error Type",
"message": "Error details",
"stackTrace": "Stack trace (development only)"
}MIT
Karunya B