{"id":23752769,"url":"https://github.com/ziv/local-storage","last_synced_at":"2025-09-05T01:32:13.743Z","repository":{"id":40566710,"uuid":"384110631","full_name":"ziv/local-storage","owner":"ziv","description":"AsyncLocalStorage middleware","archived":true,"fork":false,"pushed_at":"2024-11-11T05:05:00.000Z","size":594,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T18:25:53.601Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/ziv.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}},"created_at":"2021-07-08T12:04:06.000Z","updated_at":"2024-11-12T13:24:15.000Z","dependencies_parsed_at":"2023-02-10T01:16:42.582Z","dependency_job_id":null,"html_url":"https://github.com/ziv/local-storage","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"ziv/node-js-typescript-library-template","purl":"pkg:github/ziv/local-storage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Flocal-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Flocal-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Flocal-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Flocal-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziv","download_url":"https://codeload.github.com/ziv/local-storage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziv%2Flocal-storage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273699529,"owners_count":25152278,"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-09-04T02:00:08.968Z","response_time":61,"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":[],"created_at":"2024-12-31T17:55:39.999Z","updated_at":"2025-09-05T01:32:08.701Z","avatar_url":"https://github.com/ziv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# local-storage\n[![CI](https://github.com/ziv/local-storage/actions/workflows/main.yml/badge.svg)](https://github.com/ziv/local-storage/actions/workflows/main.yml)\n[![codecov](https://codecov.io/gh/ziv/local-storage/branch/main/graph/badge.svg?token=NTYSCHNSS1)](https://codecov.io/gh/ziv/local-storage)\n\n[AsyncLocalStorage](https://nodejs.org/api/async_context.html#async_context_class_asynclocalstorage) middleware. \n\n## Install\n```shell\nnpm i @xpr/local-storage\n```\n\n## Usage\n\n```typescript\nimport { localStorage, getStore } from '@xpr/local-storage';\n\nconst app = express();\n\n// The middleware starts an async hooks trap.\n// \n// From now on, every function called after\n// this middleware run, can access the [[Request]]\n// and the [[Response]] of the same context using\n// the [[getStore]] function.\napp.use(localStorage());\n\napp.use((req, res, next) =\u003e {\n  req.locals.RAND = generateRandNumber();\n});\n\n\nfunction logger(message: string) {\n  const store = getStore();\n  if (store) {\n    // we've been called from inside async trap\n    // we can use the store content\n    const id = store.request.locals.RAND;\n    console.log(id, message);\n  } else {\n    console.log(null, message);\n  }\n}\n```\n\n---\n\n\n![xpr-local-storage](https://badgen.net/github/license/ziv/local-storage)\n![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.svg)\n![@xpr](https://badgen.net/badge/powered%20by/@xpr/pink)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziv%2Flocal-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziv%2Flocal-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziv%2Flocal-storage/lists"}