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

@narsicloud/sqs-message-processor

v1.0.3

Published

A message processor library with retry support for serverless apps

Downloads

25

Readme

SQS Message Processor

npm version

SQS Message Processor is a reusable TypeScript library for processing AWS SQS messages with automatic retries (exponential backoff, linear, fixed) and optional Dead Letter Queue (DLQ) support. It is designed to be used in serverless projects (Lambda) or any Node.js worker application.


Features

  • ✅ Supports exponential, linear, and fixed backoff strategies
  • ✅ Handles message retries automatically
  • ✅ Supports Dead Letter Queue for failed messages
  • ✅ Works in serverless Lambda functions or polling workers
  • ✅ Fully written in TypeScript with type declarations
  • ✅ Easily reusable as an npm package

Installation

npm install @narsicloud/sqs-message-processor

Usage (Serverless / Lambda)

import { SQSClient } from "@aws-sdk/client-sqs";
import { MessageProcessor, RetryStrategies } from "sqs-message-processor";

// Create an AWS SQS client
const sqs = new SQSClient({ region: "us-east-1" });

// Create a MessageProcessor instance
const processor = new MessageProcessor({
  sqs,
  queueUrl: process.env.SQS_URL,
  dlqUrl: process.env.DLQ_URL,
  maxRetries: 5,
  retryStrategy: RetryStrategies.exponentialBackoff(5, 900),
});

// Lambda handler
export const handler = async (event: any) => {
  for (const record of event.Records) {
    await processor.processMessage(record, async (msg) => {
      const data = JSON.parse(msg.body);
      console.log("Processing:", data);

      // Example: simulate random failure
      if (Math.random() < 0.7) throw new Error("Random failure");

      console.log("Processed successfully:", data);
    });
  }
};

Retry Strategies

The library includes several built-in strategies:

Exponential Backoff

RetryStrategies.exponentialBackoff(baseDelay: number, maxDelay: number)
  • Delay grows exponentially: baseDelay * 2^attempt
  • Capped at maxDelay

Linear Backoff

RetryStrategies.linearBackoff(step: number, maxDelay: number)
  • Delay grows linearly: step * attempt
  • Capped at maxDelay

Fixed Delay

RetryStrategies.fixedDelay(delay: number)
  • Constant delay for every retry

Custom Strategy

const customRetry = (attempt: number) => attempt * 10 + Math.floor(Math.random() * 5);

API

MessageProcessor

constructor(config: MessageProcessorConfig)

Config:

  • sqs: SQSClient — AWS SQS client
  • queueUrl: string — URL of the main queue
  • dlqUrl?: string — URL of the Dead Letter Queue (optional)
  • maxRetries?: number — maximum retry attempts (default: 5)
  • retryStrategy: (attempt: number) => number — function to calculate delay in seconds

processMessage(message: any, handler: (message: any) => Promise<void>)

Processes a single SQS message with retry logic.

  • message — SQS message object
  • handler — async function containing your business logic
  • Throws an error if the message fails (optional, lets Lambda mark it as failed)