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

@allmightypush/push-express

v1.0.0

Published

Express middleware for push notification library

Downloads

79

Readme

@allmightypush/push-express

Express middleware for managing push notification subscriptions.

Installation

npm install @allmightypush/push-express @allmightypush/push-core express

Quick Start

import express from 'express';
import { createExpressMiddleware } from '@allmightypush/push-express';
import { SQLiteStorageAdapter } from '@allmightypush/push-storage-sqlite';

const app = express();
const storage = new SQLiteStorageAdapter({ filename: './push.db' });

app.use(express.json());
app.use('/api/push', createExpressMiddleware({ storageAdapter: storage }));

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

API Endpoints

POST /subscriptions

Create a new push notification subscription.

Request Body:

{
  "endpoint": "https://fcm.googleapis.com/fcm/send/...",
  "keys": {
    "p256dh": "user-public-key",
    "auth": "user-auth-secret"
  },
  "userId": "optional-user-id",
  "metadata": {
    "deviceType": "mobile",
    "appVersion": "1.0.0"
  }
}

Response: 201 Created

{
  "id": "subscription-id",
  "endpoint": "https://fcm.googleapis.com/fcm/send/...",
  "keys": { "p256dh": "...", "auth": "..." },
  "userId": "optional-user-id",
  "status": "active",
  "createdAt": "2024-01-01T00:00:00.000Z",
  "updatedAt": "2024-01-01T00:00:00.000Z"
}

GET /subscriptions/:id

Retrieve a subscription by ID.

Response: 200 OK or 404 Not Found

GET /subscriptions

List subscriptions with optional filtering and pagination.

Query Parameters:

  • userId - Filter by user ID
  • status - Filter by status (active, expired, failed)
  • limit - Maximum results (default: 100)
  • offset - Pagination offset (default: 0)

Response: 200 OK

{
  "subscriptions": [...],
  "total": 10,
  "limit": 100,
  "offset": 0
}

PATCH /subscriptions/:id

Update a subscription.

Request Body:

{
  "status": "expired",
  "metadata": { "updated": true }
}

Response: 200 OK or 404 Not Found

DELETE /subscriptions/:id

Delete a subscription.

Response: 204 No Content or 404 Not Found

Configuration Options

interface ExpressMiddlewareOptions {
  // Storage adapter for managing subscriptions (required)
  storageAdapter: StorageAdapter;

  // Optional authentication middleware
  authMiddleware?: (req, res, next) => void;

  // Custom base path (default: '')
  basePath?: string;

  // Custom validation function
  validateSubscription?: (subscription) => Promise<void> | void;
}

Examples

With Authentication

import { createExpressMiddleware } from '@allmightypush/push-express';

const authMiddleware = (req, res, next) => {
  const token = req.headers.authorization?.replace('Bearer ', '');
  
  if (!token || !isValidToken(token)) {
    return res.status(401).json({ error: 'Unauthorized' });
  }
  
  next();
};

app.use('/api/push', createExpressMiddleware({
  storageAdapter: storage,
  authMiddleware,
}));

With Custom Validation

app.use('/api/push', createExpressMiddleware({
  storageAdapter: storage,
  validateSubscription: async (data) => {
    // Ensure endpoint uses HTTPS
    if (!data.endpoint?.startsWith('https://')) {
      throw new Error('Endpoint must use HTTPS');
    }
    
    // Check against allowed domains
    const url = new URL(data.endpoint);
    if (!allowedDomains.includes(url.hostname)) {
      throw new Error('Endpoint domain not allowed');
    }
  },
}));

With Custom Base Path

app.use('/api/push', createExpressMiddleware({
  storageAdapter: storage,
  basePath: '/v1', // Routes will be /api/push/v1/subscriptions
}));

Error Handling

The middleware returns appropriate HTTP status codes:

  • 200 OK - Successful GET/PATCH
  • 201 Created - Successful POST
  • 204 No Content - Successful DELETE
  • 400 Bad Request - Invalid input
  • 401 Unauthorized - Authentication failed (if auth middleware used)
  • 404 Not Found - Resource not found
  • 500 Internal Server Error - Server error

License

MIT