{"id":21672486,"url":"https://github.com/redis-developer/basic-redis-shopping-chart-nodejs","last_synced_at":"2025-10-30T18:38:03.841Z","repository":{"id":40378632,"uuid":"336104686","full_name":"redis-developer/basic-redis-shopping-chart-nodejs","owner":"redis-developer","description":"Basic Redis Shopping cart demo using NodeJS","archived":false,"fork":false,"pushed_at":"2023-06-30T21:37:41.000Z","size":6357,"stargazers_count":23,"open_issues_count":2,"forks_count":14,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-01-25T09:27:37.263Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Vue","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/redis-developer.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":"2021-02-04T22:56:31.000Z","updated_at":"2025-01-11T10:12:05.000Z","dependencies_parsed_at":"2025-01-25T09:25:55.340Z","dependency_job_id":"3a67a14b-4541-488c-80ec-8f311cb92afd","html_url":"https://github.com/redis-developer/basic-redis-shopping-chart-nodejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-shopping-chart-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-shopping-chart-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-shopping-chart-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-shopping-chart-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis-developer","download_url":"https://codeload.github.com/redis-developer/basic-redis-shopping-chart-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244576955,"owners_count":20475217,"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":[],"created_at":"2024-11-25T13:29:32.589Z","updated_at":"2025-10-30T18:37:58.794Z","avatar_url":"https://github.com/redis-developer.png","language":"Vue","readme":"# Tutorial: A Shopping Cart app in NodeJS and Redis JSON\n\n## Technical Stack\n\n- Frontend - Vue.js\n- Backend - NodeJS, ExpressJS, Redis(Redis JSON)\n\nThis shopping cart is using Redis and Redis JSON functionalities, allowing you to save JSON as keys using methods like json_get and json_set.\n\n\n## How it works\n\n### How the data is stored:\n\n* The products data is stored in external json file. After first request this data is saved in a JSON data type in Redis like: `JSON.SET product:{productId} . '{ \"id\": \"productId\", \"name\": \"Product Name\", \"price\": \"375.00\", \"stock\": 10 }'`.\n    * E.g `JSON.SET product:e182115a-63d2-42ce-8fe0-5f696ecdfba6 . '{ \"id\": \"e182115a-63d2-42ce-8fe0-5f696ecdfba6\", \"name\": \"Brilliant Watch\", \"price\": \"250.00\", \"stock\": 2 }'`\n* The cart data is stored in a hash like: `HSET cart:{cartId} product:{productId} {productQuantity}`, where cartId is random generated value and stored in user session.\n    * E.g `HSET cart:77f7fc881edc2f558e683a230eac217d product:e182115a-63d2-42ce-8fe0-5f696ecdfba6 1`\n\n### How the data is modified:\n* The product data is modified like `JSON.SET product:{productId} . '{ \"id\": \"productId\", \"name\": \"Product Name\", \"price\": \"375.00\", \"stock\": {newStock} }'`.\n    * E.g `JSON.SET product:e182115a-63d2-42ce-8fe0-5f696ecdfba6 . '{ \"id\": \"e182115a-63d2-42ce-8fe0-5f696ecdfba6\", \"name\": \"Brilliant Watch\", \"price\": \"250.00\", \"stock\": 1 }'`\n* The cart data is modified like `HSET cart:{cartId} product:{productId} {newProductQuantity}` or `HINCRBY cart:{cartId} product:{productId} {incrementBy}`.\n    * E.g `HSET cart:77f7fc881edc2f558e683a230eac217d product:e182115a-63d2-42ce-8fe0-5f696ecdfba6 2`\n    * E.g `HINCRBY cart:77f7fc881edc2f558e683a230eac217d product:e182115a-63d2-42ce-8fe0-5f696ecdfba6 1`\n    * E.g `HINCRBY cart:77f7fc881edc2f558e683a230eac217d product:e182115a-63d2-42ce-8fe0-5f696ecdfba6 -1`\n* Product can be removed from cart like `HDEL cart:{cartId} product:{productId}`\n    * E.g `HDEL cart:77f7fc881edc2f558e683a230eac217d product:e182115a-63d2-42ce-8fe0-5f696ecdfba6`\n* Cart can be cleared using `HGETALL cart:{cartId}` and then `HDEL cart:{cartId} {productKey}` in loop.\n    * E.g `HGETALL cart:77f7fc881edc2f558e683a230eac217d` =\u003e `product:e182115a-63d2-42ce-8fe0-5f696ecdfba6`, `product:f9a6d214-1c38-47ab-a61c-c99a59438b12`, `product:1f1321bb-0542-45d0-9601-2a3d007d5842` =\u003e `HDEL cart:77f7fc881edc2f558e683a230eac217d product:e182115a-63d2-42ce-8fe0-5f696ecdfba6`, `HDEL cart:77f7fc881edc2f558e683a230eac217d product:f9a6d214-1c38-47ab-a61c-c99a59438b12`, `HDEL cart:77f7fc881edc2f558e683a230eac217d product:1f1321bb-0542-45d0-9601-2a3d007d5842`\n* All carts can be deleted when reset data is requested like: `SCAN {cursor} MATCH cart:*` and then `DEL cart:{cartId}` in loop.\n    * E.g `SCAN {cursor} MATCH cart:*` =\u003e `cart:77f7fc881edc2f558e683a230eac217d`, `cart:217dedc2f558e683a230eac77f7fc881`, `cart:1ede77f558683a230eac7fc88217dc2f` =\u003e `DEL cart:77f7fc881edc2f558e683a230eac217d`, `DEL cart:217dedc2f558e683a230eac77f7fc881`, `DEL cart:1ede77f558683a230eac7fc88217dc2f`\n\n### How the data is accessed:\n* Products: `SCAN {cursor} MATCH product:*` to get all product keys and then `JSON.GET {productKey}` in loop.\n    * E.g `SCAN {cursor} MATCH product:*` =\u003e `product:e182115a-63d2-42ce-8fe0-5f696ecdfba6`, `product:f9a6d214-1c38-47ab-a61c-c99a59438b12`, `product:1f1321bb-0542-45d0-9601-2a3d007d5842` =\u003e `JSON.GET product:e182115a-63d2-42ce-8fe0-5f696ecdfba6`, `JSON.GET product:f9a6d214-1c38-47ab-a61c-c99a59438b1`, `JSON.GET product:1f1321bb-0542-45d0-9601-2a3d007d5842`\n* Cart: `HGETALL cart:{cartId}`to get quantity of products and `JSON.GET product:{productId}` to get products data in loop.\n    * E.g `HGETALL cart:77f7fc881edc2f558e683a230eac217d`  =\u003e `product:e182115a-63d2-42ce-8fe0-5f696ecdfba6 (quantity: 1)`, `product:f9a6d214-1c38-47ab-a61c-c99a59438b12 (quantity: 0)`, `product:1f1321bb-0542-45d0-9601-2a3d007d5842 (quantity: 2)` =\u003e `JSON.GET product:e182115a-63d2-42ce-8fe0-5f696ecdfba6`, `JSON.GET product:f9a6d214-1c38-47ab-a61c-c99a59438b12`, `JSON.GET product:1f1321bb-0542-45d0-9601-2a3d007d5842`\n    * HGETALL returns array of keys and corresponding values from hash data type.\n\n## Hot to run it locally?\n\n### Prerequisites\n\n- Node - v12.19.0\n- NPM - v6.14.8\n- Docker - v19.03.13 (optional)\n\n### Local installation\n\nGo to server folder (`cd ./server`) and then:\n\n```\n# Environmental variables\n\nCopy `.env.example` to `.env` file and fill environmental variables\n\nREDIS_PORT: Redis port (default: 6379)\nREDIS_HOST: Redis host (default: 127.0.0.1)\nREDIS_PASSWORD: Redis password (default: demo)\n\ncp .env.example .env\n\n# Run docker compose or install redis with RedisJson module manually. You can also go to https://redislabs.com/try-free/ and obtain necessary environmental variables\n\ndocker network create global\ndocker-compose up -d --build\n\n# Install dependencies\n\nnpm install\n\n# Run dev server\n\nnpm run dev\n```\n\nGo to client folder (`cd ./client`) and then:\n\n```\n# Environmental variables\n\nCopy `.env.example` to `.env` file\n\ncp .env.example .env\n\n# Install dependencies\n\nnpm install\n\n# Serve locally\n\nnpm run serve\n```\n\n## Deployment\n\nTo make deploys work, you need to create free account in https://redislabs.com/try-free/, create Redis instance with `RedisJson` module and get informations - REDIS_ENDPOINT_URI and REDIS_PASSWORD. You must pass them as environmental variables.\n\n### Google Cloud Run\n\n[![Run on Google\nCloud](https://deploy.cloud.run/button.svg)](https://deploy.cloud.run/?git_repo=https://github.com/redis-developer/basic-redis-shopping-chart-nodejs.git)\n\n### Heroku\n\n[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)\n\n### Vercel\n\n[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/redis-developer/basic-redis-shopping-chart-nodejs\u0026env=REDIS_ENDPOINT_URI,REDIS_PASSWORD)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fbasic-redis-shopping-chart-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis-developer%2Fbasic-redis-shopping-chart-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fbasic-redis-shopping-chart-nodejs/lists"}