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

@dnardev/common

v2.0.1

Published

Common library for dnar microservices

Readme

Dnar Common Library

A comprehensive shared library for Dnar microservices providing common functionality, utilities, and integrations.

Features

Core Modules

  • Authentication - JWT authentication guards and utilities
  • Database - TypeORM integration and PostgreSQL connection management
  • Kafka - Message queue integration with producers and consumers
  • Logger - Centralized logging with Pino integration
  • Redis - Redis client management and caching utilities

Integrations & Utilities

  • Config - Environment-based configuration management (Database, Redis, JWT, KYC, Tatum)
  • Middleware - Express middleware for CORS, security, validation, error handling
  • Types - Common TypeScript interfaces and types
  • Utils - Utility functions for responses, validation, and data transformation
  • Binance - Lightweight REST client for Binance spot API (prices, order book, account data)
  • Tatum - Configuration for Tatum Blockchain API (wallets, addresses, balances). See docs/TATUM_CONFIGURATION.md for use with Skudo Business Services.

Installation

pnpm install @dnar/common

Usage

Basic Import

import {
  logger,
  configManager,
  db,
  redis,
  cors,
  errorHandler,
  ApiResponse,
} from "@dnar/common";

Configuration Management

import { configManager, getDatabaseConfig, getRedisConfig } from "@dnar/common";

// Get specific configurations
const dbConfig = getDatabaseConfig();
const redisConfig = getRedisConfig();

// Validate configuration
configManager.validateConfig();

Database Operations

import { db, query, transaction } from "@dnar/common";

// Simple query
const result = await query("SELECT * FROM users WHERE id = $1", [userId]);

// Transaction
await transaction(async (client) => {
  await client.query("INSERT INTO users (name) VALUES ($1)", ["John"]);
  await client.query("UPDATE counters SET count = count + 1");
});

Redis Operations

import { redis, set, get, setJSON, getJSON } from "@dnar/common";

// Basic operations
await set("key", "value", 3600); // with TTL
const value = await get("key");

// JSON operations
await setJSON("user:123", { name: "John", age: 30 }, 3600);
const user = await getJSON("user:123");

Middleware

import express from "express";
import { cors, security, errorHandler, requestLogger } from "@dnar/common";

const app = express();

app.use(cors);
app.use(security);
app.use(requestLogger);
app.use(errorHandler);

Logging

import { logger, createLogger } from "@dnar/common";

// Use default logger
logger.info("Application started");

// Create service-specific logger
const serviceLogger = createLogger("user-service");
serviceLogger.error("User not found", { userId: "123" });

Response Utilities

import {
  createSuccessResponse,
  createErrorResponse,
  sendSuccessResponse,
  sendErrorResponse,
} from "@dnar/common";

// Create response objects
const successResponse = createSuccessResponse(data, "Operation successful");
const errorResponse = createErrorResponse("User not found", "USER_NOT_FOUND");

// Send responses in Express
sendSuccessResponse(res, data, "User created successfully");
sendErrorResponse(res, "Validation failed", 400);

Binance Integration

import { BinanceClient } from "@dnar/common";

const binance = new BinanceClient({
  apiKey: process.env.BINANCE_API_KEY,
  apiSecret: process.env.BINANCE_API_SECRET,
});

// Fetch latest ticker price
const { price } = await binance.getTickerPrice("BTCUSDT");

// Weighted average price
const avg = await binance.getAveragePrice("ETHUSDT");

// Account overview (requires API credentials with trading permissions)
const account = await binance.getAccountInformation();

Configuration

The library uses environment variables for configuration. Key variables include:

Database

  • DATABASE_URL - Full database connection string
  • DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD
  • DB_SSL - Enable SSL connection
  • DB_MAX_CONNECTIONS - Connection pool size

Redis

  • REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, REDIS_DB
  • REDIS_MAX_RETRIES - Connection retry attempts

JWT

  • JWT_SECRET - Secret key for JWT signing
  • JWT_EXPIRATION - Token expiration time
  • JWT_ALGORITHM - Signing algorithm (HS256, HS384, HS512)

Tatum (optional)

  • TATUM_API_KEY - Tatum API key (enables Tatum when set; used for v3 and v4)
  • TATUM_API_KEY_V4 - Tatum API key v4 (alternative to TATUM_API_KEY)
  • TATUM_API_KEY_V3 - Tatum API key v3 (optional; defaults to same as v4 if only one key set)
  • TATUM_NETWORK - e.g. ethereum-sepolia, bitcoin-testnet (default: ethereum-sepolia)
  • TATUM_BASE_URL - Override API base URL
  • TATUM_TIMEOUT - Request timeout in ms (default: 30000)
  • TATUM_VERBOSE - Set to true for verbose logging

Service Configuration

  • CORS_ORIGIN - Allowed CORS origins
  • RATE_LIMIT_WINDOW_MS - Rate limiting window
  • RATE_LIMIT_MAX_REQUESTS - Maximum requests per window
  • LOG_LEVEL - Logging level (debug, info, warn, error)

Development

Install dependencies

pnpm install

Build the library

pnpm run build

Prepare changes for versioning

pnpm changeset

Release

pnpm run release

Migration Notes

This library now includes functionality migrated from the Skudo Business Services project:

  • Config Management: Centralized configuration with environment variable support
  • Database Manager: PostgreSQL connection pooling and query management
  • Redis Manager: Redis client with pub/sub support and JSON operations
  • Middleware: Express middleware for security, CORS, validation, and error handling
  • Types: Common TypeScript interfaces for API responses, pagination, etc.
  • Utils: Utility functions for data transformation, validation, and response formatting

All original Dnar Common functionality remains intact and compatible.