{"id":15400038,"url":"https://github.com/mcollina/fastify-asyncforge","last_synced_at":"2025-04-16T01:52:35.640Z","repository":{"id":234510384,"uuid":"789011707","full_name":"mcollina/fastify-asyncforge","owner":"mcollina","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-24T10:38:03.000Z","size":85,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-02T01:05:44.550Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mcollina.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":"2024-04-19T14:28:32.000Z","updated_at":"2024-05-11T08:36:21.174Z","dependencies_parsed_at":"2024-05-11T08:46:31.545Z","dependency_job_id":null,"html_url":"https://github.com/mcollina/fastify-asyncforge","commit_stats":null,"previous_names":["mcollina/fastify-asyncforge"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Ffastify-asyncforge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Ffastify-asyncforge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Ffastify-asyncforge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcollina%2Ffastify-asyncforge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcollina","download_url":"https://codeload.github.com/mcollina/fastify-asyncforge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249183064,"owners_count":21226140,"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-10-01T15:51:32.225Z","updated_at":"2025-04-16T01:52:35.618Z","avatar_url":"https://github.com/mcollina.png","language":"JavaScript","readme":"# fastify-asyncforge\n\nProvide easy [AsyncLocalStorage](https://nodejs.org/api/async_context.html) magic to your\n[Fastify](https://fastify.dev) apps. It's based on [asyncforge](http://npm.im/asyncforge).\n\n## Install\n\n```sh\nnpm i fastify fastify-asyncforge\n```\n\n## Usage\n\n```js\n// app.mjs\nimport fastify from 'fastify'\nimport doWork from './do-work.mjs'\nimport asyncforge, { logger } from 'fastify-asyncforge'\n\nconst app = fastify({\n  logger: true\n})\nawait app.register(asyncforge)\n\napp.runInAsyncScope(() =\u003e {\n  logger().info('hello')\n})\n\napp.decorate('foo', 'bar')\napp.decorateRequest('a')\napp.decorateReply('b')\n\napp.addHook('onRequest', async function (req, reply) {\n  req.a = 'a'\n  reply.b = 'b'\n})\n\napp.get('/', async function (request, reply) {\n  doWork()\n  return { hello: 'world' }\n})\n\napp.listen({ port: 3000 })\n\n// do-work.mjs\nimport { logger, app, request, reply } from 'fastify-asyncforge'\n\nexport default function doWork () {\n  const log = logger()\n  log.info({\n    foo: app().foo,\n    a: request().a,\n    b: reply().b\n  }, 'doing work')\n}\n```\n\n## `.enterWith()`\n\nIn case `.runInAsyncScope()` is incovenient, you can use `.enterWith()`\n\n```js\nimport fastify from 'fastify'\nimport asyncforge from 'fastify-asyncforge'\n\nconst fastify = Fastify()\n\n// Calling .enterWith() is necessary or `asyncforge.app()` will throw\nfastify.enterWith()\nasyncforge.app()\n```\n\n### Notice\n\nNote that you cannot wrap `.enterWith()` inside an async function, as it will not work.\nIf you are interested in knowing more, read https://github.com/nodejs/node/issues/53037.\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcollina%2Ffastify-asyncforge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcollina%2Ffastify-asyncforge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcollina%2Ffastify-asyncforge/lists"}