{"id":26120559,"url":"https://github.com/yevhenlisovenko/nodejs-nano-service","last_synced_at":"2026-04-17T23:35:46.918Z","repository":{"id":281492947,"uuid":"945473301","full_name":"yevhenlisovenko/nodejs-nano-service","owner":"yevhenlisovenko","description":"A lightweight event-driven microservices package for RabbitMQ in Node.js. Enables asynchronous communication, message publishing and consuming, and scalable event-driven architecture. Perfect for distributed systems and real-time applications.","archived":false,"fork":false,"pushed_at":"2025-03-24T11:51:42.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-12T21:12:28.242Z","etag":null,"topics":["async","cloud-native","distributed-systems","event-bus","event-driven","event-processing","high-performance","message-broker","message-queue","microservices","nodejs","pubsub","queueing","rabbitmq","scalable-architecture"],"latest_commit_sha":null,"homepage":"https://awescode.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yevhenlisovenko.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-03-09T14:07:45.000Z","updated_at":"2025-03-24T11:51:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"21a2e90c-ecb5-4862-a774-7883bc651c66","html_url":"https://github.com/yevhenlisovenko/nodejs-nano-service","commit_stats":null,"previous_names":["yevhenlisovenko/nodejs-nano-service"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/yevhenlisovenko/nodejs-nano-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yevhenlisovenko%2Fnodejs-nano-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yevhenlisovenko%2Fnodejs-nano-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yevhenlisovenko%2Fnodejs-nano-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yevhenlisovenko%2Fnodejs-nano-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yevhenlisovenko","download_url":"https://codeload.github.com/yevhenlisovenko/nodejs-nano-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yevhenlisovenko%2Fnodejs-nano-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31950647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["async","cloud-native","distributed-systems","event-bus","event-driven","event-processing","high-performance","message-broker","message-queue","microservices","nodejs","pubsub","queueing","rabbitmq","scalable-architecture"],"created_at":"2025-03-10T13:43:07.851Z","updated_at":"2026-04-17T23:35:46.909Z","avatar_url":"https://github.com/yevhenlisovenko.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NodeJS Nano-Service\n\n## Introduction\n\nNodeJS Nano-Service is a lightweight event-driven microservices package for **RabbitMQ**. It allows seamless **message publishing and consuming** within a **Node.js microservices architecture**, ensuring **scalability, reliability, and efficiency** in **distributed systems**.\n\n## Features\n\n- 📡 **Event-Driven Architecture** – Publish and consume messages efficiently\n- 🚀 **Scalable \u0026 High-Performance** – Ideal for real-time applications\n- 🔄 **Standardized Messages** – Uses `NanoServiceMessage` for structured event communication\n- 🎯 **Microservice-Ready** – `NanoServiceClass` makes integration simple\n- 🌐 **Supports AMQP/RabbitMQ** – Built-in support for RabbitMQ message brokering\n- 📊 **Enterprise-Level Logging** – Uses **Winston** for logging and **Sentry** for error tracking\n- 🛠️ **Easily Extensible** – Add custom event handlers for business logic\n\n## Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/your-username/nodejs-nano-service.git\n   cd nodejs-nano-service\n   ```\n\n2. Install dependencies:\n\n   ```bash\n   npm install\n   ```\n\n3. Set up environment variables:\n   Create a `.env` file in the root directory with the following variables:\n   ```env\n   AMQP_PROJECT=bus-e2e\n   AMQP_MICROSERVICE_NAME=project-name\n   AMQP_HOST=127.0.0.1\n   AMQP_PORT=5672\n   AMQP_USER=user\n   AMQP_PASS=\n   AMQP_VHOST=bus-e2e\n   ```\n\n## Usage\n\n### Publishing Messages\n\nTo publish a message, use the `NanoPublisher` class:\n\n```javascript\nconst { NanoPublisher, NanoServiceMessage } = require(\"nodejs-nano-service\");\n\n(async () =\u003e {\n  const publisher = new NanoPublisher();\n  const message = new NanoServiceMessage({ payload: { key: \"value\" } });\n\n  await publisher\n    .setMessage(message)\n    .setMeta({ tenant: \"example-tenant\" })\n    .delay(5000) // 5-second delay\n    .publish(\"company.created\");\n})();\n```\n\n### Consuming Messages\n\nTo consume messages, use the `NanoConsumer` class:\n\n```javascript\nconst { NanoConsumer } = require(\"nodejs-nano-service\");\nconst handlers = require(\"./handlers\");\n\nconst EVENT_HANDLERS = {\n  \"company.created\": handlers.CustomerCreatedHandler,\n};\n\n(async () =\u003e {\n  const consumer = new NanoConsumer()\n    .events(...Object.keys(EVENT_HANDLERS)) // Bind to user-defined events\n    .tries(4) // Retry up to 4 times\n    .backoff([5, 15, 60, 300]) // Backoff intervals in seconds\n    .catch((error, message) =\u003e {\n      console.error(\"⚠️ Catchable error\", {\n        error: error.message,\n        event: message.getEventName(),\n      });\n    })\n    .failed((error, message) =\u003e {\n      console.error(\"❌ Permanent error\", {\n        error: error.message,\n        event: message.getEventName(),\n      });\n    });\n\n  await consumer.consume(async (message) =\u003e {\n    const handler = EVENT_HANDLERS[message.getEventName()];\n    if (handler) {\n      await handler(message);\n      console.log(`✅ Handled event: ${message.getEventName()}`);\n    } else {\n      console.warn(`⚠️ No handler for event: ${message.getEventName()}`);\n    }\n  });\n})();\n```\n\n### Example Handlers\n\nDefine your event handlers in a separate file (e.g., `handlers.js`):\n\n```javascript\nmodule.exports = {\n  CustomerCreatedHandler: async (message) =\u003e {\n    const payload = message.getPayload();\n    console.log(\"Handling company.created event:\", payload);\n    // Add your business logic here\n  },\n};\n```\n\n## Configuration\n\n### Environment Variables\n\n| Variable                 | Description                          | Example Value          |\n| ------------------------ | ------------------------------------ | ---------------------- |\n| `AMQP_PROJECT`           | Project namespace for RabbitMQ       | `easyweek-e2e`         |\n| `AMQP_MICROSERVICE_NAME` | Microservice name for RabbitMQ queue | `demo-nodejs`          |\n| `AMQP_HOST`              | RabbitMQ host                        | `127.0.0.1`            |\n| `AMQP_PORT`              | RabbitMQ port                        | `5672`                 |\n| `AMQP_USER`              | RabbitMQ username                    | `user`                 |\n| `AMQP_PASS`              | RabbitMQ password                    | `ohCuYNimH2kq1UBuciOX` |\n| `AMQP_VHOST`             | RabbitMQ virtual host                | `easyweek-e2e`         |\n\n### Retry and Backoff\n\n- **Retry Attempts**: Configure the number of retry attempts using the `tries` method.\n- **Backoff Intervals**: Configure backoff intervals (in seconds) using the `backoff` method.\n\nExample:\n\n```javascript\nconst consumer = new NanoConsumer()\n  .tries(4) // Retry up to 4 times\n  .backoff([5, 15, 60, 300]); // Backoff intervals: 5s, 15s, 60s, 300s\n```\n\n## Logging\n\nThe project uses `winston` for logging. Logs are output in JSON format to the console.\n\nExample log output:\n\n```json\n{\"level\":\"info\",\"message\":\"🚀 Starting consumer: easyweek-e2e.demo-nodejs\"}\n{\"level\":\"info\",\"message\":\"✅ Handled event: company.created\"}\n{\"level\":\"error\",\"message\":\"⚠️ Catchable error\",\"error\":\"Some error message\",\"event\":\"company.created\"}\n```\n\n## Error Handling\n\n- **Transient Errors**: Use the `catch` method to handle transient errors (e.g., network issues).\n- **Permanent Errors**: Use the `failed` method to handle permanent errors (e.g., invalid data).\n\nExample:\n\n```javascript\nconst consumer = new NanoConsumer()\n  .catch((error, message) =\u003e {\n    console.error(\"⚠️ Catchable error\", {\n      error: error.message,\n      event: message.getEventName(),\n    });\n  })\n  .failed((error, message) =\u003e {\n    console.error(\"❌ Permanent error\", {\n      error: error.message,\n      event: message.getEventName(),\n    });\n  });\n```\n\n## Contributing\n\nContributions are welcome! Please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch for your feature or bugfix.\n3. Submit a pull request with a detailed description of your changes.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\nThis `README.md` provides a clear and concise overview of your project, making it easy for users and contributors to understand and use your library. You can customize it further based on your specific needs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyevhenlisovenko%2Fnodejs-nano-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyevhenlisovenko%2Fnodejs-nano-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyevhenlisovenko%2Fnodejs-nano-service/lists"}