npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nodejs-nano-service

v1.3.0

Published

A lightweight event-driven microservices package for RabbitMQ in Node.js. Enables scalable message publishing and consuming for distributed systems.

Readme

NodeJS Nano-Service

Introduction

NodeJS 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.

Features

  • 📡 Event-Driven Architecture – Publish and consume messages efficiently
  • 🚀 Scalable & High-Performance – Ideal for real-time applications
  • 🔄 Standardized Messages – Uses NanoServiceMessage for structured event communication
  • 🎯 Microservice-ReadyNanoServiceClass makes integration simple
  • 🌐 Supports AMQP/RabbitMQ – Built-in support for RabbitMQ message brokering
  • 📊 Enterprise-Level Logging – Uses Winston for logging and Sentry for error tracking
  • 🛠️ Easily Extensible – Add custom event handlers for business logic

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/nodejs-nano-service.git
    cd nodejs-nano-service
  2. Install dependencies:

    npm install
  3. Set up environment variables: Create a .env file in the root directory with the following variables:

    AMQP_PROJECT=bus-e2e
    AMQP_MICROSERVICE_NAME=project-name
    AMQP_HOST=127.0.0.1
    AMQP_PORT=5672
    AMQP_USER=user
    AMQP_PASS=
    AMQP_VHOST=bus-e2e

Usage

Publishing Messages

To publish a message, use the NanoPublisher class:

const { NanoPublisher, NanoServiceMessage } = require("nodejs-nano-service");

(async () => {
  const publisher = new NanoPublisher();
  const message = new NanoServiceMessage({ payload: { key: "value" } });

  await publisher
    .setMessage(message)
    .setMeta({ tenant: "example-tenant" })
    .delay(5000) // 5-second delay
    .publish("company.created");
})();

Consuming Messages

To consume messages, use the NanoConsumer class:

const { NanoConsumer } = require("nodejs-nano-service");
const handlers = require("./handlers");

const EVENT_HANDLERS = {
  "company.created": handlers.CustomerCreatedHandler,
};

(async () => {
  const consumer = new NanoConsumer()
    .events(...Object.keys(EVENT_HANDLERS)) // Bind to user-defined events
    .tries(4) // Retry up to 4 times
    .backoff([5, 15, 60, 300]) // Backoff intervals in seconds
    .catch((error, message) => {
      console.error("⚠️ Catchable error", {
        error: error.message,
        event: message.getEventName(),
      });
    })
    .failed((error, message) => {
      console.error("❌ Permanent error", {
        error: error.message,
        event: message.getEventName(),
      });
    });

  await consumer.consume(async (message) => {
    const handler = EVENT_HANDLERS[message.getEventName()];
    if (handler) {
      await handler(message);
      console.log(`✅ Handled event: ${message.getEventName()}`);
    } else {
      console.warn(`⚠️ No handler for event: ${message.getEventName()}`);
    }
  });
})();

Example Handlers

Define your event handlers in a separate file (e.g., handlers.js):

module.exports = {
  CustomerCreatedHandler: async (message) => {
    const payload = message.getPayload();
    console.log("Handling company.created event:", payload);
    // Add your business logic here
  },
};

Configuration

Environment Variables

| Variable | Description | Example Value | | ------------------------ | ------------------------------------ | ---------------------- | | AMQP_PROJECT | Project namespace for RabbitMQ | easyweek-e2e | | AMQP_MICROSERVICE_NAME | Microservice name for RabbitMQ queue | demo-nodejs | | AMQP_HOST | RabbitMQ host | 127.0.0.1 | | AMQP_PORT | RabbitMQ port | 5672 | | AMQP_USER | RabbitMQ username | user | | AMQP_PASS | RabbitMQ password | ohCuYNimH2kq1UBuciOX | | AMQP_VHOST | RabbitMQ virtual host | easyweek-e2e |

Retry and Backoff

  • Retry Attempts: Configure the number of retry attempts using the tries method.
  • Backoff Intervals: Configure backoff intervals (in seconds) using the backoff method.

Example:

const consumer = new NanoConsumer()
  .tries(4) // Retry up to 4 times
  .backoff([5, 15, 60, 300]); // Backoff intervals: 5s, 15s, 60s, 300s

Logging

The project uses winston for logging. Logs are output in JSON format to the console.

Example log output:

{"level":"info","message":"🚀 Starting consumer: easyweek-e2e.demo-nodejs"}
{"level":"info","message":"✅ Handled event: company.created"}
{"level":"error","message":"⚠️ Catchable error","error":"Some error message","event":"company.created"}

Error Handling

  • Transient Errors: Use the catch method to handle transient errors (e.g., network issues).
  • Permanent Errors: Use the failed method to handle permanent errors (e.g., invalid data).

Example:

const consumer = new NanoConsumer()
  .catch((error, message) => {
    console.error("⚠️ Catchable error", {
      error: error.message,
      event: message.getEventName(),
    });
  })
  .failed((error, message) => {
    console.error("❌ Permanent error", {
      error: error.message,
      event: message.getEventName(),
    });
  });

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request with a detailed description of your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.


This 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.