{"id":26282889,"url":"https://github.com/sasmithx/nodejs-restapi-aws-ec2-ci-cd-pipeline","last_synced_at":"2026-01-18T12:35:08.506Z","repository":{"id":282382120,"uuid":"948278382","full_name":"sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline","owner":"sasmithx","description":"A Node.js REST API deployed on AWS EC2 with a CI/CD pipeline for automated testing, building, and deployment.","archived":false,"fork":false,"pushed_at":"2025-03-14T10:06:27.000Z","size":1090,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T08:44:06.620Z","etag":null,"topics":["aws","aws-ec2-intances","ci-cd-pipeline","devops","github-work","nginx","pm2"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sasmithx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2025-03-14T03:34:54.000Z","updated_at":"2025-03-14T10:23:34.000Z","dependencies_parsed_at":"2025-03-14T10:28:03.688Z","dependency_job_id":"6df8c5d0-29a3-4fa7-a601-ee4125d15069","html_url":"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline","commit_stats":null,"previous_names":["sasmithx/nodejs-restapi-aws-ec2-ci-cd-pipeline"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasmithx%2FNodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasmithx%2FNodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasmithx%2FNodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasmithx%2FNodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sasmithx","download_url":"https://codeload.github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252852815,"owners_count":21814415,"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":["aws","aws-ec2-intances","ci-cd-pipeline","devops","github-work","nginx","pm2"],"created_at":"2025-03-14T17:15:56.841Z","updated_at":"2026-01-18T12:35:08.497Z","avatar_url":"https://github.com/sasmithx.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Automating Node.js REST API Deployment on AWS EC2 with CI/CD\n\nThis repository contains a Node.js REST API application deployed on AWS EC2. It includes a CI/CD pipeline for continuous integration and continuous deployment, enabling automated testing, building, and deployment processes. The project demonstrates best practices for developing and deploying scalable REST APIs with seamless integration into AWS services.\n\nFirst, set up Node.js server, which will act as the backbone of our REST API. This server will handle requests, process data, and communicate with the database to ensure seamless functionality.\n##\n\n\n1. Clone the repository:\n\n   ```bash\n   https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline.git\n   ```\n\nThis will provide a structured starting point for building and integrating your API.\n\nSince we are using MongoDB as our database, it is essential to configure its accessibility properly. To ensure seamless connectivity from any location, update the network access settings accordingly, allowing external access while maintaining security best practices.\n\n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/MongoDB.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/MongoDB.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e\n\n2. Setting Up EC2 Instance and Git Repository\n\n- Create a new EC2 instance in your AWS account.\n- Generate or use an existing SSH key pair for accessing the instance.\n- Create a new Git repository and push your Node.js code to it.\n\n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/EC2.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/EC2.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e\n\n3. Connecting to EC2 Instance\n\n- After creating the instance and pushing code to the repository, connect to the EC2 instance via SSH using the .pem file.\n\n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/ConnectEC2.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/ConnectEC2.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e\n\n```\nssh -i your-key.pem ubuntu@your-ec2-public-ip\n```\n\n4. Setting Up GitHub Actions\n\n- Navigate to your repository settings on GitHub and select Actions.\n- Add a self-hosted runner and follow the setup instructions\n\n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/Runners.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/Runners.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e  \n\n5. Environment Setup for GitHub Actions\n\n- Create a .env file with your environment variables and add them as secrets in your GitHub repository settings.\n\n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/Secret.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/Secret.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e\n\n6. CI/CD Workflows\n\n- Create GitHub Actions workflows for CI/CD. Below is an example of a Node.js CI workflow.\n\n```\n# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node\n# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs\n\nname: Node.js CI/CD\n\non:\n  push:\n    branches: [ \"main\" ]\n\njobs:\n  build:\n    runs-on: self-hosted\n    strategy:\n      matrix:\n        node-version: [22.x]\n        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/\n    steps:\n    - uses: actions/checkout@v3\n    - name: Use Node.js ${{ matrix.node-version }}\n      uses: actions/setup-node@v3\n      with:\n        node-version: ${{ matrix.node-version }}\n        cache: 'npm'\n    - run: npm ci\n    - run: |\n        touch .env\n        echo \"${{ secrets.MONGO_DB_URL }}\" \u003e .env\n    - run: pm2 restart BackendAPI\n```\n\n7. Environment Setup in Ubuntu\n\n```\nsudo ./svc.sh install\nsudo ./svc.sh start\n\n```\nEnsure Node.js and Nginx are installed on your Ubuntu instance.\n\n```\nsudo apt update\ncurl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -\nsudo apt-get install -y nodejs nginx\n\n```\n\n8. Setting Up Nginx Reverse Proxy\n\nConfigure Nginx to act as a reverse proxy for your Node.js application.\n\n```\nsudo nano /etc/nginx/sites-available/default\n\n```\n\nAdd the following configuration,\n\n```\nlocation /api {\n  rewrite ^\\/api\\/(.*)$ /api/$1 break;\n  proxy_pass http://localhost:5000;\n  proxy_set_header Host $host;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n}\n\n```\n\nRestart Nginx for changes to take effect,\n\n```\nsudo systemctl restart nginx\n\n```\n\n9. Setting Up PM2\n\nPM2 is a process manager for Node.js applications. Install and configure it to keep your application running in the background.\n\n```\nsudo npm i -g pm2\npm2 start server.js --name=apiServer\n\n```\n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/PM2Start.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/PM2Start.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/PM2.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/PM2.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e\n\n10. Now changes are directly applying in to the CI/CD pipeline for every new push and pull in to the main branch.\n    \n  \u003ca href=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/Workflows.png\"\u003e\n    \u003cimg src=\"https://github.com/sasmithx/Nodejs-RESTAPI-AWS-EC2-CI-CD-Pipeline/blob/main/assets/Workflows.png\" style=\"border-radius: 40px;\" \u003e\n  \u003c/a\u003e\n\nUpon successful completion of the CI process, the CD (Continuous Deployment) phase is initiated.\n\n## **📌 License**  \n\nDistributed under the MIT License. See [LICENSE](LICENSE) for more information.\n\n---\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/git-%23F05033.svg?style=for-the-badge\u0026logo=git\u0026logoColor=white\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge\u0026logo=github\u0026logoColor=white\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge\u0026logo=node.js\u0026logoColor=white\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/AWS-000000?style=for-the-badge\u0026logo=amazonaws\u0026logoColor=FF9900\" /\u003e \n  \u003cimg src=\"https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge\u0026logo=mongodb\u0026logoColor=white\" /\u003e \n  \u003cimg src=\"https://img.shields.io/badge/Nginx-000000?style=for-the-badge\u0026logo=nginx\u0026logoColor=009639\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge\u0026logo=javascript\u0026logoColor=black\" /\u003e\n  \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasmithx%2Fnodejs-restapi-aws-ec2-ci-cd-pipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsasmithx%2Fnodejs-restapi-aws-ec2-ci-cd-pipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasmithx%2Fnodejs-restapi-aws-ec2-ci-cd-pipeline/lists"}