{"id":15862346,"url":"https://github.com/sydrawat01/rest-api","last_synced_at":"2025-10-04T02:06:12.014Z","repository":{"id":94883912,"uuid":"601207925","full_name":"sydrawat01/rest-api","owner":"sydrawat01","description":"Production-ready REST API with Docker, Hashicorp Packer, custom error handlers and ES7+ support","archived":false,"fork":false,"pushed_at":"2024-01-12T20:35:24.000Z","size":327,"stargazers_count":4,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T09:43:22.868Z","etag":null,"topics":["aws-ami","bash-script","docker","error-handling","es7","expressjs","hashicorp-packer","nodejs","packer","postgresql","production","rest-api","sequelize","sequelize-orm","winston-logger"],"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/sydrawat01.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2023-02-13T15:35:41.000Z","updated_at":"2025-05-15T19:20:16.000Z","dependencies_parsed_at":"2024-01-12T22:48:56.049Z","dependency_job_id":"5fe54643-8805-4dcf-8261-6250639b15da","html_url":"https://github.com/sydrawat01/rest-api","commit_stats":null,"previous_names":[],"tags_count":5,"template":true,"template_full_name":null,"purl":"pkg:github/sydrawat01/rest-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sydrawat01%2Frest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sydrawat01%2Frest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sydrawat01%2Frest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sydrawat01%2Frest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sydrawat01","download_url":"https://codeload.github.com/sydrawat01/rest-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sydrawat01%2Frest-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278254466,"owners_count":25956604,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-ami","bash-script","docker","error-handling","es7","expressjs","hashicorp-packer","nodejs","packer","postgresql","production","rest-api","sequelize","sequelize-orm","winston-logger"],"created_at":"2024-10-05T22:40:29.788Z","updated_at":"2025-10-04T02:06:11.998Z","avatar_url":"https://github.com/sydrawat01.png","language":"JavaScript","readme":"# REST API\n\n[![Unit Tests](https://github.com/sydrawat01/rest-api/actions/workflows/unit-test.yml/badge.svg)](https://github.com/sydrawat01/rest-api/actions/workflows/unit-test.yml) [![Packer AMI template validation](https://github.com/sydrawat01/rest-api/actions/workflows/packer-validate.yml/badge.svg)](https://github.com/sydrawat01/rest-api/actions/workflows/packer-validate.yml) [![Build](https://github.com/sydrawat01/rest-api/actions/workflows/packer-build.yml/badge.svg)](https://github.com/sydrawat01/rest-api/actions/workflows/packer-build.yml) [![Release](https://github.com/sydrawat01/rest-api/actions/workflows/release.yml/badge.svg)](https://github.com/sydrawat01/rest-api/actions/workflows/release.yml)\n\nThis is a basic skeleton code to create a basic REST API using NodeJS, ExpressJS and Babel.\n\n\u003e \\[!NOTE]\\\n\u003e NOTE: Please note that this is still a work in progress.\n\n## Features\n\n- ES7+\n- NodeJS\n- ExpressJS\n- Winston for logging\n- Basic test scripts\n- Custom error handlers\n- PostgreSQL and Sequelize\n- Bcrypt\n- Custom Amazon Machine Image using Hashicorp Packer\n- Containerization using Docker\n\n## Planned features\n\n- AWS S3, DynamoDB and SNS Topics\n- Email verification of user\n- TypeScript support\n\n## Connect to local db\n\n```shell\n\npsql postgres\n\nCREATE ROLE me WITH LOGIN PASSWORD 'password';\nALTER ROLE me CREATEDB;\n\npsql -d postgres -U me\n\nCREATE DATABASE test;\n\n\\c test\n\nselect * from users;\n```\n\n## Docker\n\nThis is an example repository that will help you dockerize your Node+Express application using Docker.\n\n1. Create a simple REST API with the following endpoints:\n\n- `/` that returns OK status code (200)\n- `/health` that returns OK status code(200)\n\n2. Create a simple test that checks the health routes.\n\n3. Create a new file named `Dockerfile` at the root of the repository.\n\n4. Add the following configuration to the above created file:\n\n```docker\n# which node to use for your container\nFROM node:alpine\n\n# the directory where the appication will be copied to in your container\nWORKDIR /usr/src/app\n\n# copy the contents of the base(app) directory to the container WORKDIR\nCOPY . .\n\n# commands to run to install dependencies\nRUN npm install\n\n# port that must be exposed to the client where the application is running in the container\nEXPOSE 3000\n\n# command to start the application in the container\nCMD [\"yarn\", \"start\"]\n```\n\n5. Now, to create an image of your basic REST API:\n\n```shell\n# -t option to tag the image with a version\n# if a version is not provided, the default tag is 'latest'\n# the '.' option at the end is to build the current working directory\ndocker build -t \u003cimage-name\u003e:\u003cimage-version\u003e .\n```\n\nExample:\n\n```shell\ndocker build -t api:v1 .\n```\n\nTo create a docker image using another version of a `Dockerfile`, use the following command:\n\n```shell\ndocker build -t \u003cimage-name\u003e:\u003cimage-version\u003e -f \u003cDockerfile-name\u003e .\n```\n\nExample:\n\n```shell\ndocker build -t api:v2 -f Dockerfile.dev .\n```\n\n6. To verify your image is build and ready:\n\n```shell\n# lists all images that docker has built or pulled from docker hub\ndocker images\n```\n\n7. To create and run a container:\n\n```shell\n# -ti is to run the container in an interactive terminal mode\n# --name is to name your container\n# -p is to expose the port from the container to the local machine where the container is running\ndocker run -ti --name \u003ccontainer-name\u003e \\\n-p \u003clocal-machine-port\u003e:\u003ccontainer-port\u003e \\\n\u003cimage-name\u003e:\u003cimage-version\u003e\n```\n\nExample:\n\n```shell\ndocker run -ti --name rest-api-container -p 3000:1337 api:v1\n```\n\n8. Test the API endpoints using `Postman` on `http://localhost:3000`.\n\n9. To stop a running container:\n\n```shell\ndocker container stop \u003ccontainer-name\u003e\n```\n\nExample:\n\n```shell\ndocker container stop gpt-container\n```\n\n10. To restart a stopped container:\n\n```shell\ndocker container start \u003ccontainer-name\u003e\n```\n\nExample:\n\n```shell\ndocker container start gpt-container\n```\n\nTo enter the `bash` terminal within the container:\n\n```shell\ndocker exec -ti \u003ccontainer-name\u003e bash\n```\n\nExample:\n\n```shell\ndocker exec -ti gpt-container bash\n```\n\n### Docker bind mount\n\nThe `-v` flag represents the volume in our container, where our application will be uploaded in the Docker Ubuntu image.\n\n```shell\ndocker run --name \u003ccontainer-name\u003e \\\n-p \u003clocal-machine-port\u003e:\u003ccontainer-port\u003e \\\n-v \u003clocal-machine-dir\u003e:\u003ccontainer-WORKDIR-PATH\u003e \\\n\u003cimage-name\u003e:\u003cimage-version\u003e\n```\n\nExample:\n\n```shell\ndocker run --name rest-api-container-2 \\\n-p 3000:1337 \\\n-v $(pwd):/usr/src/app \\\napi:v1\n```\n\n\u003e NOTE: If you are on a windows computer, `$(pwd)` will not work. Instead, use `%cd%`.\n\n### Anonymous volume\n\nTo leave the `node_modules` directory untouched in the local machine directory, and to not track it in the docker container, we use anonymous volumes.\n\n```shell\ndocker run --name \u003ccontainer-name\u003e \\\n-p \u003clocal-machine-port\u003e:\u003ccontainer-port\u003e \\\n-v \u003clocal-machine-dir\u003e:\u003ccontainer-WORKDIR-PATH\u003e \\\n-v \u003ccontainer-WORKDIR/node_modules\u003e \\\n\u003cimage-name\u003e:\u003cimage-version\u003e\n```\n\nExample:\n\n```shell\ndocker run --name rest-api-container-3\n-p 3000:1337 \\\n-v $(pwd):/usr/src/app \\\n-v /usr/src/app/node_modules \\\napi:v1\n```\n\nSince we do not have the `:` colon to link this volume in our container to the local machine directory, this is an anonymous volume.\n\n### SSH into a container\n\n```shell\ndocker exec -ti \u003ccontainer-name\u003e /bin/sh\n```\n\nExample:\n\n```shell\ndocker exec -ti rest-api-container-3 /bin/sh\n```\n\n### Stop and delete containers\n\n1. Look for the container name:\n\n```shell\ndocker ps\n```\n\n2. Stop the container using the container name:\n\n```shell\ndocker stop \u003ccontainer-name\u003e\n```\n\nExample:\n\n```shell\n╰─ docker ps\nCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                    NAMES\n15fa4c6bbd11   api:v2    \"docker-entrypoint.s…\"   8 seconds ago   Up 6 seconds   0.0.0.0:3000-\u003e1337/tcp   rest-api\n```\n\n```shell\ndocker stop rest-api\n```\n\n3. To check for stopped containers:\n\n```shell\ndocker ps -a\n```\n\n4. Make sure that the container is stopped, then proceed to remove that container.\n\n```shell\ndocker ps;\ndocker rm \u003ccontainer-name\u003e\n```\n\nExample:\n\n```shell\ndocker rm rest-api\n```\n\n### Delete docker images\n\nTo delete docker images:\n\n1. Check the name of the image you want to delete:\n\n```shell\ndocker images\n```\n\n2. Delete the image by it's name:\n\n```shell\ndocker image rm \u003cimage-name\u003e:\u003cimage-version\u003e\n```\n\nExample:\n\n```shell\n# check for docker images\ndocker images\n```\n\n```shell\n# output\n╰─ docker images\nREPOSITORY   TAG       IMAGE ID       CREATED       SIZE\napi          v3        4d74db3e5ada   7 hours ago   366MB\napi          v2        7bc302778f7c   7 hours ago   366MB\n```\n\n```shell\n# remove the desired docker image\ndocker image rm api:v2\n```\n\n### Work in progress\n\nDo not build `.env` into the docker image.\n\n## Author\n\n[Siddharth Rawat](mailto:sydrawat@gmail.com)\n\n## License\n\n[MIT License](./LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsydrawat01%2Frest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsydrawat01%2Frest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsydrawat01%2Frest-api/lists"}