A robust backend API for user authentication and form handling built with Node.js, Express, and MongoDB.
- User authentication (Login/Register/Logout)
- JWT based authorization
- File upload support
- Secure password handling
- CORS enabled
- Error handling middleware
- Environmental variables support
- Node.js
- Express.js
- MongoDB
- JWT (JSON Web Tokens)
- Bcrypt
- Multer
- Cloudinary
src/
├── controllers/ # Route controllers
├── models/ # Database models
├── routes/ # API routes
├── middlewares/ # Custom middlewares
├── utils/ # Utility functions
└── db/ # Database configuration
- POST
/api/v1/users/register- Register new user - POST
/api/v1/users/login- Login user - POST
/api/v1/users/logout- Logout user
- GET
/api/v1/users/profile- Get user profile - PATCH
/api/v1/users/update- Update user details - PATCH
/api/v1/users/password- Change password
Create a .env file in the root directory:
PORT=8000
MONGODB_URI=your_mongodb_connection_string
ACCESS_TOKEN_SECRET=your_access_token_secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=your_refresh_token_secret
REFRESH_TOKEN_EXPIRY=10d
CORS_ORIGIN=http://localhost:5173- Clone the repository:
git clone <repository-url>- Install dependencies:
cd Backend
npm install- Set up environment variables:
cp .env.sample .env- Start the development server:
npm run devnpm run dev- Start development servernpm start- Start production servernpm run lint- Run ESLintnpm test- Run tests
The API uses a custom error handling mechanism:
ApiErrorclass for consistent error responses- Standardized error format
- Proper HTTP status codes
- Password hashing using bcrypt
- JWT token-based authentication
- Request rate limiting
- HTTP security headers
- XSS protection
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.