{"id":17397684,"url":"https://github.com/ducktors/fastify-moleculer","last_synced_at":"2026-01-28T05:24:07.700Z","repository":{"id":257827448,"uuid":"872944016","full_name":"ducktors/fastify-moleculer","owner":"ducktors","description":"Fastify plugin for moleculerjs","archived":false,"fork":false,"pushed_at":"2024-10-24T17:44:47.000Z","size":133,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-25T10:27:16.666Z","etag":null,"topics":["fastify","fastify-plugin","moleculer","moleculerjs"],"latest_commit_sha":null,"homepage":"","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/ducktors.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":"2024-10-15T10:47:07.000Z","updated_at":"2024-10-24T17:44:48.000Z","dependencies_parsed_at":"2024-11-08T18:26:45.062Z","dependency_job_id":"316b44ef-b0f0-44e3-89c5-5d6b423588b0","html_url":"https://github.com/ducktors/fastify-moleculer","commit_stats":null,"previous_names":["ducktors/fastify-moleculer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducktors%2Ffastify-moleculer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducktors%2Ffastify-moleculer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducktors%2Ffastify-moleculer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducktors%2Ffastify-moleculer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ducktors","download_url":"https://codeload.github.com/ducktors/fastify-moleculer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228526766,"owners_count":17933291,"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":["fastify","fastify-plugin","moleculer","moleculerjs"],"created_at":"2024-10-16T14:03:32.679Z","updated_at":"2026-01-28T05:24:02.681Z","avatar_url":"https://github.com/ducktors.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-moleculer\n\n[![Build](https://github.com/ducktors/fastify-moleculer/actions/workflows/build.yaml/badge.svg)](https://github.com/ducktors/fastify-moleculer/actions/workflows/build.yaml) [![Test](https://github.com/ducktors/fastify-moleculer/actions/workflows/test.yaml/badge.svg)](https://github.com/ducktors/fastify-moleculer/actions/workflows/test.yaml) [![npm](https://img.shields.io/npm/v/fastify-moleculer)](https://www.npmjs.com/package/fastify-moleculer) [![Coverage Status](https://coveralls.io/repos/github/ducktors/fastify-moleculer/badge.svg?branch=main)](https://coveralls.io/github/ducktors/fastify-moleculer?branch=main) [![Maintainability](https://api.codeclimate.com/v1/badges/8415332abe3ff865131d/maintainability)](https://codeclimate.com/github/ducktors/fastify-moleculer/maintainability) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/ducktors/fastify-moleculer/badge)](https://securityscorecards.dev/viewer/?uri=github.com/ducktors/fastify-moleculer)\n\n`fastify-moleculer` enables the use of [Moleculer](https://moleculer.services/) in a Fastify application.\n\n## Features\n- Full TypeScript support\n- Compatible with Fastify `4.x`\n- Compatible with Moleculer `0.14`\n- Automatic service discovery and loading\n- Built-in cleanup hooks\n- Zero configuration required\n\n## Installation\n\n```bash\n# Using npm\nnpm install fastify-moleculer moleculer\n\n# Using pnpm\npnpm add fastify-moleculer moleculer\n\n# Using yarn\nyarn add fastify-moleculer moleculer\n```\n\n## Configuration\n\n### Plugin Options\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `serviceFolder` | `string` | `undefined` | Directory to load services from |\n| `serviceMask` | `string` | `*.service.(js\\|ts)` | File pattern for service discovery |\n| `preClose` | `(done: () =\u003e void) =\u003e void` | `undefined` | Hook called before broker shutdown |\n\n## Usage\n\nRequire `fastify-moleculer` and register it as any other plugin, it will add a `broker` decorator.\n\n`serviceFolder` \u0026 `serviceMask` options respect the configuration supported by moleculer [ServiceBroker](https://moleculer.services/docs/0.14/broker)\n\n```js\nconst fastify = require(\"fastify\")();\n\nfastify.register(require(\"fastify-moleculer\"), {\n  // put your options here\n  serviceFolder: './',          //load all services from the given folder\n  serviceMask: '*.service.js'   //load all services whose file nane respect the given mask\n});\n\nfastify.get(\"/\", (req, reply) =\u003e {\n  fastify.broker.emit(\"hello\", { who: 'world' });\n});\n\nfastify.listen({ port: 3000 });\n```\n\nFor more details see [examples](https://github.com/ducktors/fastify-moleculer/tree/master/examples)\n\nYou can use it as is without passing any option, or you can configure it as explained by Moleculer [doc](https://moleculer.services/docs/0.14/configuration).\n\n### Hooks\n\nThe plugin support a `preClose` hook to clean up loaded services in order to close correctly the fastify server. To configure this behaviour you can use `preClose` option:\n\n```javascript\nawait fastify.register(require('fastify-moleculer'), {\n  preClose: (done) =\u003e {\n    // do other things\n    // fastify.broker. ;\n    done();\n  }\n})\n```\n\nThe plugin also adds an `onClose` hook which closes the socket server when the `fastify` instance is closed.\n\n## Typescript\n\nThe `broker` decorator is typed to moleculer [ServiceBroker](https://moleculer.services/docs/0.14/broker) type.\nThe plugin supports loading Typescript service classes from a given folder optionally overriding the default file mask of `.service.(js|ts)`.\n\n## Contribute to this project\n\n1. Clone this repository\n\n   `git clone git@github.com:github.com/ducktors/fastify-moleculer.git`\n\n2. Move inside repository folder\n\n   `cd fastify-moleculer`\n\n3. Install dependencies\n\n   `pnpm install`\n\n## How to release\n\nThe release is performed by the maintainers of the repository. New versions are managed via [changesets](https://github.com/changesets/changesets).\n\nTo release a new version, simply choose which package to bump with `pnpm release` command:\n\n```\n$ pnpm release\n\n\u003e @ducktors/fastify-moleculer@0.9.0 release /ducktors-workstation/fastify-moleculer\n\u003e changeset\n\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\u003cbr/\u003e\n[`moleculer` license](https://github.com/moleculerjs/moleculer/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducktors%2Ffastify-moleculer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fducktors%2Ffastify-moleculer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducktors%2Ffastify-moleculer/lists"}