REST API for managing feature flags, built with Node.js, Express, and MongoDB.
-
Feature Flag Management
- Create, read, update, and delete feature flags
- Toggle features on/off
- Track flag creation and updates
-
Authentication & Authorization
- JWT-based authentication
- Role-based access control (User/Admin)
- Secure password hashing with bcryptjs
-
Security Features
- Rate limiting to prevent abuse
- Helmet for HTTP security headers
- CORS enabled
- Request validation
-
Logging & Monitoring
- Winston logger implementation
- Morgan HTTP request logging
- Error tracking and handling
-
API Documentation
- Swagger/OpenAPI documentation
- Detailed API endpoints documentation
- Request/Response examples
- Node.js & Express.js
- MongoDB with Mongoose
- JWT for authentication
- Winston & Morgan for logging
- Express-validator for validation
- Swagger for API documentation
Once the server is running, you can access the Swagger documentation at:
http://localhost:3000/api-docs-
Clone the repository:
git clone <repository-url> cd feature-flag-api
-
Install dependencies:
npm install
-
Create a .env file in the root directory:
NODE_ENV=development PORT=3000 MONGO_URI=mongodb://localhost:27017/featureflags JWT_SECRET=your_jwt_secret_key JWT_EXPIRE=30d
-
Start the server:
# Development mode npm run dev # Production mode npm start
POST /api/auth/register - Register a new user
POST /api/auth/login - Login user
GET /api/auth/me - Get current userGET /api/flags - Get all feature flags
POST /api/flags - Create new feature flag
GET /api/flags/:id - Get specific feature flag
PUT /api/flags/:id - Update feature flag
DELETE /api/flags/:id - Delete feature flagGET /api/users - Get all users (Admin only)
GET /api/users/:id - Get specific user (Admin only)
PUT /api/users/:id - Update user (Admin only)
DELETE /api/users/:id - Delete user (Admin only)The API implements centralized error handling with proper HTTP status codes and error messages. Common error responses:
- 400: Bad Request (Invalid input)
- 401: Unauthorized (Invalid/missing token)
- 403: Forbidden (Insufficient permissions)
- 404: Not Found
- 429: Too Many Requests
- 500: Internal Server Error
-
Rate Limiting
- 100 requests per 15 minutes per IP
-
Security Headers
- Implemented using Helmet middleware
- XSS protection
- Prevention of clickjacking
- Strict Transport Security
-
Request Validation
- Input validation using express-validator
- MongoDB injection prevention
- Request sanitization
Logs are stored in the logs directory:
error.log: Error logs onlycombined.log: All logs