A modern RESTful API built with Express.js and MongoDB that combines secure user account management with comprehensive contact operations. Features JWT authentication, user profiles, contact management, and automated testing suite.
- User Authentication (Register, Login, JWT)
- Contact Management
- MongoDB Integration
- Error Handling
- Input Validation
- Automated Testing
- Node.js (v14 or higher)
- MongoDB
- npm or yarn
- Clone the repository:
git clone https://github.com/yourusername/user-vault-api.git
cd user-vault-api
- Install dependencies:
npm install
- Set up environment variables:
- Copy
.env.example
to create your.env
file:cp .env.example .env
- Update the values in
.env
with your configuration:PORT
: API server port (default: 3000)MONGODB_URI
: Your MongoDB connection stringACCESS_TOKEN_SECRET
: JWT signing secret (generate a secure random string)JWT_SECRET
: Backup JWT secret (generate a secure random string)NODE_ENV
: Environment setting (development/test/production)
- Copy
Development mode:
npm start
Run tests:
npm test
POST /api/users/register
- Register new userPOST /api/users/login
- Login userGET /api/users/current
- Get current user (Protected)DELETE /api/users/delete-user
- Delete user (Protected)
GET /api/contacts
- Get all contacts (Protected)POST /api/contacts
- Create contact (Protected)GET /api/contacts/:id
- Get single contact (Protected)PUT /api/contacts/:id
- Update contact (Protected)DELETE /api/contacts/:id
- Delete contact (Protected)
The API includes comprehensive test suites and a detailed testing guide:
- See
TESTING.md
for API testing instructions - Postman collection included for API testing
- Automated tests for all endpoints
- Error handling tests
Run automated tests with:
npm test
The API implements proper error handling with appropriate HTTP status codes and error messages.
MIT License