{"id":28610932,"url":"https://github.com/manujb023/ci-cd-node-api","last_synced_at":"2025-06-11T23:07:55.169Z","repository":{"id":298226244,"uuid":"999273229","full_name":"ManuJB023/ci-cd-node-api","owner":"ManuJB023","description":"Automated CI/CD Pipeline for Node.js API on AWS EC2 using GitHub Actions, CodeDeploy, and PM2. This project demonstrates a complete DevOps workflow that automatically deploys a Node.js backend to an EC2 instance on every push to the main branch, ensuring zero-downtime releases with PM2 and AWS CodeDeploy.","archived":false,"fork":false,"pushed_at":"2025-06-10T02:33:22.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-10T03:29:59.402Z","etag":null,"topics":["automation","aws-codedeploy","backend","continuous-deployment","continuous-integration","deployment","devops","ec2","github-actions","nodejs","pm2"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ManuJB023.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-10T02:28:26.000Z","updated_at":"2025-06-10T02:49:34.000Z","dependencies_parsed_at":"2025-06-10T03:40:14.426Z","dependency_job_id":null,"html_url":"https://github.com/ManuJB023/ci-cd-node-api","commit_stats":null,"previous_names":["manujb023/ci-cd-node-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ManuJB023/ci-cd-node-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManuJB023%2Fci-cd-node-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManuJB023%2Fci-cd-node-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManuJB023%2Fci-cd-node-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManuJB023%2Fci-cd-node-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ManuJB023","download_url":"https://codeload.github.com/ManuJB023/ci-cd-node-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManuJB023%2Fci-cd-node-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259361007,"owners_count":22845828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","aws-codedeploy","backend","continuous-deployment","continuous-integration","deployment","devops","ec2","github-actions","nodejs","pm2"],"created_at":"2025-06-11T23:07:53.676Z","updated_at":"2025-06-11T23:07:55.156Z","avatar_url":"https://github.com/ManuJB023.png","language":"JavaScript","readme":"# CI/CD Node.js API\n\nA production-ready RESTful API built with Node.js and Express.js, designed to demonstrate modern development practices, comprehensive testing, and CI/CD pipeline integration.\n\n## 🚀 Features\n\n- **Complete CRUD Operations** for user management\n- **Advanced Filtering \u0026 Pagination** for scalable data retrieval\n- **Input Validation \u0026 Sanitization** with detailed error responses\n- **Comprehensive Testing Suite** with 22+ test cases\n- **Health Monitoring** with system metrics\n- **Request Logging** for debugging and monitoring\n- **Graceful Shutdown** handling for production deployments\n- **Environment-aware Configuration** for different deployment stages\n\n## 📋 Table of Contents\n\n- [Quick Start](#quick-start)\n- [API Documentation](#api-documentation)\n- [Real-World Use Cases](#real-world-use-cases)\n- [Testing](#testing)\n- [Development](#development)\n- [CI/CD Integration](#cicd-integration)\n- [Production Deployment](#production-deployment)\n- [Contributing](#contributing)\n\n## 🎯 Quick Start\n\n### Prerequisites\n\n- Node.js (v14 or higher)\n- npm or yarn\n- Git\n\n### Installation\n\n```bash\n# Clone the repository\ngit clone \u003cyour-repository-url\u003e\ncd ci-cd-node-api\n\n# Install dependencies\nnpm install\n\n# Start development server\nnpm run dev\n\n# Run tests\nnpm test\n\n# Check code quality\nnpm run lint\n```\n\nThe API will be available at `http://localhost:3000`\n\n## 📚 API Documentation\n\n### Base URL\n```\nhttp://localhost:3000\n```\n\n### Endpoints Overview\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | `/` | Welcome message and API info |\n| GET | `/health` | Health check with system metrics |\n| GET | `/api/users` | Get all users (with filtering \u0026 pagination) |\n| GET | `/api/users/:id` | Get specific user by ID |\n| POST | `/api/users` | Create new user |\n| PUT | `/api/users/:id` | Update existing user |\n| DELETE | `/api/users/:id` | Delete user |\n| GET | `/api/stats` | API statistics |\n\n### Detailed API Reference\n\n#### 1. Welcome Endpoint\n```http\nGET /\n```\n\n**Response:**\n```json\n{\n  \"message\": \"Welcome to the CI/CD Node API\",\n  \"version\": \"1.0.0\",\n  \"environment\": \"development\",\n  \"timestamp\": \"2024-01-15T10:30:00.000Z\",\n  \"endpoints\": {\n    \"health\": \"/health\",\n    \"users\": \"/api/users\",\n    \"documentation\": \"See README.md for full API documentation\"\n  }\n}\n```\n\n#### 2. Health Check\n```http\nGET /health\n```\n\n**Response:**\n```json\n{\n  \"status\": \"healthy\",\n  \"uptime\": 3600,\n  \"timestamp\": \"2024-01-15T10:30:00.000Z\",\n  \"memory\": {\n    \"used\": \"45 MB\",\n    \"total\": \"128 MB\"\n  },\n  \"version\": \"1.0.0\"\n}\n```\n\n#### 3. Get Users (with Advanced Features)\n```http\nGET /api/users?page=1\u0026limit=10\u0026name=john\u0026email=doe\n```\n\n**Query Parameters:**\n- `page` (optional): Page number for pagination (default: 1)\n- `limit` (optional): Items per page (default: 10)\n- `name` (optional): Filter by name (case-insensitive partial match)\n- `email` (optional): Filter by email (case-insensitive partial match)\n\n**Response:**\n```json\n{\n  \"users\": [\n    {\n      \"id\": 1,\n      \"name\": \"John Doe\",\n      \"email\": \"john@example.com\",\n      \"createdAt\": \"2024-01-15T10:00:00.000Z\",\n      \"updatedAt\": \"2024-01-15T10:00:00.000Z\"\n    }\n  ],\n  \"pagination\": {\n    \"currentPage\": 1,\n    \"totalPages\": 5,\n    \"totalUsers\": 50,\n    \"hasNext\": true,\n    \"hasPrev\": false\n  }\n}\n```\n\n#### 4. Get User by ID\n```http\nGET /api/users/1\n```\n\n**Response:**\n```json\n{\n  \"id\": 1,\n  \"name\": \"John Doe\",\n  \"email\": \"john@example.com\",\n  \"createdAt\": \"2024-01-15T10:00:00.000Z\",\n  \"updatedAt\": \"2024-01-15T10:00:00.000Z\"\n}\n```\n\n#### 5. Create User\n```http\nPOST /api/users\nContent-Type: application/json\n\n{\n  \"name\": \"Jane Smith\",\n  \"email\": \"jane@example.com\"\n}\n```\n\n**Response:**\n```json\n{\n  \"message\": \"User created successfully\",\n  \"user\": {\n    \"id\": 4,\n    \"name\": \"Jane Smith\",\n    \"email\": \"jane@example.com\",\n    \"createdAt\": \"2024-01-15T10:30:00.000Z\",\n    \"updatedAt\": \"2024-01-15T10:30:00.000Z\"\n  }\n}\n```\n\n#### 6. Update User\n```http\nPUT /api/users/1\nContent-Type: application/json\n\n{\n  \"name\": \"John Updated\",\n  \"email\": \"john.updated@example.com\"\n}\n```\n\n#### 7. Delete User\n```http\nDELETE /api/users/1\n```\n\n**Response:**\n```json\n{\n  \"message\": \"User deleted successfully\",\n  \"deletedUser\": {\n    \"id\": 1,\n    \"name\": \"John Doe\",\n    \"email\": \"john@example.com\"\n  }\n}\n```\n\n#### 8. API Statistics\n```http\nGET /api/stats\n```\n\n**Response:**\n```json\n{\n  \"totalUsers\": 25,\n  \"apiVersion\": \"1.0.0\",\n  \"uptime\": 7200,\n  \"timestamp\": \"2024-01-15T10:30:00.000Z\"\n}\n```\n\n### Error Responses\n\nThe API returns consistent error responses:\n\n```json\n{\n  \"error\": \"Error message\",\n  \"details\": {\n    \"field\": \"Specific field error\"\n  }\n}\n```\n\n**Common Status Codes:**\n- `200` - Success\n- `201` - Created\n- `400` - Bad Request (validation errors)\n- `404` - Not Found\n- `409` - Conflict (duplicate email)\n- `500` - Internal Server Error\n\n## 🌍 Real-World Use Cases\n\nThis API architecture and implementation pattern is commonly used in various real-world scenarios:\n\n### 1. **E-commerce Platforms**\n- **User Management**: Customer registration, profile updates, account management\n- **Product Catalogs**: With filtering, pagination, and search capabilities\n- **Order Processing**: CRUD operations for orders, inventory management\n- **Example**: Building a customer portal where users can manage their profiles, view order history, and update preferences\n\n### 2. **SaaS Applications**\n- **Multi-tenant User Management**: Managing users across different organizations\n- **Feature Access Control**: User roles and permissions management\n- **Analytics Dashboards**: APIs for fetching user engagement metrics\n- **Example**: A project management tool where teams can invite members, assign roles, and track user activity\n\n### 3. **Social Media \u0026 Content Platforms**\n- **User Profiles**: Registration, authentication, profile management\n- **Content Management**: Posts, comments, media uploads with pagination\n- **Social Features**: Friends, followers, notifications\n- **Example**: A blogging platform where authors can manage their profiles, publish articles, and interact with readers\n\n### 4. **Enterprise Applications**\n- **Employee Management Systems**: HR applications for managing staff data\n- **CRM Systems**: Customer relationship management with search and filtering\n- **Inventory Management**: Product tracking with advanced filtering capabilities\n- **Example**: An HR portal where managers can view employee profiles, update information, and generate reports\n\n### 5. **Mobile App Backends**\n- **User Authentication**: Registration and login for mobile apps\n- **Data Synchronization**: Offline-first mobile apps with server sync\n- **Push Notifications**: User preference management for notifications\n- **Example**: A fitness tracking app where users sync their workout data, manage preferences, and view progress\n\n### 6. **IoT \u0026 Device Management**\n- **Device Registration**: Managing connected devices and sensors\n- **Data Collection**: APIs for receiving and processing sensor data\n- **User Dashboards**: Interfaces for monitoring device status\n- **Example**: A smart home system where users can manage their connected devices, set preferences, and monitor usage\n\n### 7. **Educational Platforms**\n- **Student Management**: Course enrollment, progress tracking\n- **Content Delivery**: Learning materials with search and filtering\n- **Assessment Systems**: Quiz and assignment management\n- **Example**: An online learning platform where instructors manage student profiles, track progress, and deliver content\n\n### 8. **Healthcare Applications**\n- **Patient Management**: Secure handling of patient data (HIPAA compliant)\n- **Appointment Systems**: Scheduling and management APIs\n- **Medical Records**: Document management with search capabilities\n- **Example**: A telemedicine platform where doctors can manage patient profiles, schedule appointments, and access medical histories\n\n### 9. **Financial Services**\n- **Customer Profiles**: KYC (Know Your Customer) data management\n- **Transaction Processing**: Secure financial transaction APIs\n- **Compliance Reporting**: Data retrieval for regulatory requirements\n- **Example**: A fintech app where users can manage their financial profiles, view transaction history, and update preferences\n\n### 10. **API-First Businesses**\n- **Third-party Integrations**: Providing APIs for external developers\n- **Microservices Architecture**: Building scalable, maintainable systems\n- **Developer Platforms**: APIs that other developers build upon\n- **Example**: A payment processing service that provides APIs for e-commerce platforms to integrate payment functionality\n\n## 🧪 Testing\n\n### Running Tests\n\n```bash\n# Run all tests\nnpm test\n\n# Run tests in watch mode\nnpm run test:watch\n\n# Run tests with coverage\nnpm run test:coverage\n```\n\n### Test Structure\n\nThe test suite covers:\n- **Endpoint Testing**: All HTTP methods and routes\n- **Validation Testing**: Input validation and error handling\n- **Edge Cases**: Invalid IDs, missing data, duplicate entries\n- **Response Structure**: Ensuring consistent API responses\n- **Performance**: Basic performance and memory usage checks\n\n### Test Categories\n\n1. **Unit Tests**: Individual function testing\n2. **Integration Tests**: API endpoint testing\n3. **Error Handling Tests**: Exception and error response testing\n4. **Validation Tests**: Input validation and sanitization\n\n## 👨‍💻 Development\n\n### Project Structure\n\n```\nci-cd-node-api/\n├── __tests__/\n│   └── server.test.js          # Comprehensive test suite\n├── node_modules/\n├── .gitignore\n├── package.json\n├── README.md\n└── server.js                   # Main application file\n```\n\n### Development Scripts\n\n```bash\n# Start development server with auto-reload\nnpm run dev\n\n# Start production server\nnpm start\n\n# Run linting\nnpm run lint\n\n# Fix linting issues\nnpm run lint:fix\n\n# Run tests\nnpm test\n```\n\n### Code Quality\n\n- **ESLint**: Enforces code style and catches common errors\n- **Jest**: Comprehensive testing framework\n- **Consistent Error Handling**: Standardized error responses\n- **Input Validation**: Robust validation for all endpoints\n- **Security Best Practices**: Input sanitization and error message handling\n\n## 🔄 CI/CD Integration\n\nThis project is designed for seamless CI/CD integration:\n\n### GitHub Actions Example\n\n```yaml\nname: CI/CD Pipeline\n\non:\n  push:\n    branches: [ main, develop ]\n  pull_request:\n    branches: [ main ]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    \n    steps:\n    - uses: actions/checkout@v2\n    \n    - name: Setup Node.js\n      uses: actions/setup-node@v2\n      with:\n        node-version: '16'\n        \n    - name: Install dependencies\n      run: npm ci\n      \n    - name: Run linting\n      run: npm run lint\n      \n    - name: Run tests\n      run: npm test\n      \n    - name: Run security audit\n      run: npm audit\n\n  deploy:\n    needs: test\n    runs-on: ubuntu-latest\n    if: github.ref == 'refs/heads/main'\n    \n    steps:\n    - name: Deploy to production\n      run: |\n        # Add your deployment commands here\n        echo \"Deploying to production...\"\n```\n\n### Pipeline Stages\n\n1. **Linting**: Code quality checks\n2. **Testing**: Comprehensive test suite execution\n3. **Security Audit**: Dependency vulnerability scanning\n4. **Build**: Application building (if needed)\n5. **Deploy**: Automated deployment to staging/production\n\n## 🚀 Production Deployment\n\n### Environment Variables\n\n```bash\n# Production environment\nNODE_ENV=production\nPORT=3000\n\n# Database configuration (if using a database)\nDATABASE_URL=your-database-url\n\n# Logging\nLOG_LEVEL=info\n```\n\n### Docker Support\n\n```dockerfile\nFROM node:16-alpine\n\nWORKDIR /app\n\nCOPY package*.json ./\nRUN npm ci --only=production\n\nCOPY . .\n\nEXPOSE 3000\n\nUSER node\n\nCMD [\"npm\", \"start\"]\n```\n\n### Health Checks\n\nThe `/health` endpoint provides:\n- Application status\n- System uptime\n- Memory usage\n- Version information\n\nPerfect for:\n- Load balancer health checks\n- Container orchestration (Kubernetes)\n- Monitoring systems integration\n\n### Monitoring Integration\n\nThe API provides metrics suitable for:\n- **Prometheus**: Custom metrics collection\n- **Datadog**: APM and infrastructure monitoring\n- **New Relic**: Application performance monitoring\n- **AWS CloudWatch**: Cloud-native monitoring\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n### Development Guidelines\n\n- Write tests for new features\n- Follow existing code style\n- Update documentation\n- Ensure all tests pass\n- Add meaningful commit messages\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🔗 Resources\n\n- [Express.js Documentation](https://expressjs.com/)\n- [Jest Testing Framework](https://jestjs.io/)\n- [Node.js Best Practices](https://github.com/goldbergyoni/nodebestpractices)\n- [REST API Design Guidelines](https://restfulapi.net/)\n\n---\n\n**Built with ❤️ using Node.js, Express.js, and modern development practices.**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanujb023%2Fci-cd-node-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanujb023%2Fci-cd-node-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanujb023%2Fci-cd-node-api/lists"}