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

@designofadecade/server

v6.1.0

Published

Design of a Decade Server - A modern TypeScript server with WebSocket support

Readme

Design of a Decade Server

License: MIT npm version Node.js Version TypeScript Build Status

A modern, type-safe Node.js server framework with built-in WebSocket support, routing, static file handling, and middleware capabilities. Built with TypeScript for Node.js 24+.

Features

  • ✅ Full TypeScript support with comprehensive type definitions
  • ✅ ESM (ES Modules) compatible
  • Secure error handling with automatic sensitive data protection
  • ✅ WebSocket server with message formatting and event handling
  • ✅ Flexible routing system with URL pattern matching
  • ✅ Static file serving with MIME type detection
  • ✅ Built-in middleware support (request logging, etc.)
  • ✅ Application state management
  • ✅ Event system with pub/sub pattern
  • ✅ HTML sanitization utilities
  • ✅ Comprehensive test coverage with Vitest
  • ✅ Modern async/await API

📦 Installation

npm install @designofadecade/server

Or using other package managers:

# Yarn
yarn add @designofadecade/server

# pnpm
pnpm add @designofadecade/server

# Bun
bun add @designofadecade/server

Requirements

  • Node.js >= 24.0.0
  • ES Modules support (package uses "type": "module")
  • TypeScript >= 5.0 (if using TypeScript)

Quick Start

import { Server } from '@designofadecade/server';

// Create a new server instance
const server = new Server({
  port: 3000,
  hostname: 'localhost'
});

// Start the server
await server.start();
console.log('Server running on http://localhost:3000');

Architecture Overview

The server is composed of several modular components:

Server Core

  • Server: Main HTTP/HTTPS server with WebSocket upgrade support
  • Router: URL pattern-based routing with request handlers
  • Routes: Route collection and management

WebSocket Support

  • WebSocketServer: WebSocket connection management
  • WebSocketMessageFormatter: Message serialization/deserialization

Middleware & Utilities

  • RequestLogger: HTTP request logging middleware
  • StaticFileHandler: Static file serving with caching
  • HtmlSanitizer: XSS protection for HTML content
  • HtmlRenderer: Server-side HTML rendering

State & Events

  • AppState: Application-wide state management
  • Events: Event emitter with type-safe event handling
  • EventsManager: Event subscription and lifecycle management

Storage

  • Local: Local file system utilities

Integrations

  • Slack: Slack notifications integration
  • ApiClient: HTTP client for external APIs

Usage Examples

Basic Routing

import { Router } from '@designofadecade/server';

const router = new Router();

// Add routes
router.addRoute({
  pattern: '/api/users/:id',
  method: 'GET',
  handler: async (req, res, params) => {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ userId: params.id }));
  }
});

// Handle requests
await router.route(request, response);

WebSocket Communication

import { WebSocketServer } from '@designofadecade/server';

const wsServer = new WebSocketServer({ port: 8080 });

wsServer.on('connection', (ws) => {
  console.log('Client connected');
  
  ws.on('message', (data) => {
    console.log('Received:', data);
    ws.send('Echo: ' + data);
  });
});

Static File Serving

import { StaticFileHandler } from '@designofadecade/server';

const staticHandler = new StaticFileHandler({
  rootDir: './public',
  cacheControl: 'public, max-age=3600'
});

await staticHandler.serve(request, response, '/assets/style.css');

Event System

import { Events, EventsManager } from '@designofadecade/server';

const events = new Events();
const manager = new EventsManager(events);

// Subscribe to events
manager.on('user:login', (data) => {
  console.log('User logged in:', data);
});

// Emit events
events.emit('user:login', { userId: 123, timestamp: Date.now() });

Documentation

Comprehensive documentation is available in the /docs directory:

Development

Install Dependencies

npm install

Run Tests

npm test                 # Run tests once
npm run test:watch      # Run tests in watch mode
npm run test:ui         # Open Vitest UI
npm run test:coverage   # Generate coverage report

Build

npm run build           # Build once
npm run build:watch     # Build in watch mode

Linting & Formatting

npm run lint            # Run ESLint
npm run format          # Format code with Prettier
npm run typecheck       # Type-check without emitting

Project Structure

src/
├── client/             # API client utilities
├── context/            # Request context handling
├── docs/               # OpenAPI/Swagger documentation generators
├── events/             # Event system with pub/sub pattern
├── local/              # Local storage utilities
├── logger/             # Logging utilities with CloudWatch support
├── middleware/         # Request middleware (logging, etc.)
├── notifications/      # Notification integrations (Slack, etc.)
├── router/             # Routing system with URL pattern matching
├── sanitizer/          # HTML sanitization for XSS protection
├── server/             # Core HTTP/HTTPS server implementation
├── state/              # Application state management
├── types/              # TypeScript type definitions
├── utils/              # Utilities and helpers
└── websocket/          # WebSocket server implementation

API Reference

Full API documentation is available in the docs directory:

Security

This package includes built-in security features:

  • HTML Sanitization - XSS protection for user-generated content
  • Type Safety - Full TypeScript support for compile-time safety
  • Input Validation - URL pattern matching and parameter validation

If you discover a security vulnerability, please send an email to [email protected] instead of using the issue tracker.

Versioning

This project follows Semantic Versioning. For available versions, see the tags on this repository or the npm registry.

See CHANGELOG.md for a history of changes.

Support

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details on:

  • Code of Conduct
  • Development workflow
  • Pull request process
  • Coding standards
  • Testing requirements

License

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

Author

Design of a Decade
Email: [email protected]
Website: designofadecade.com

Links

Acknowledgments

Built with:

  • TypeScript - Type-safe JavaScript
  • Vitest - Unit testing framework
  • ws - WebSocket implementation

Made with ❤️ by Design of a Decade