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

psi-notification-server

v1.0.0

Published

A custom module for real-time notifications built with Express, Socket.IO, and Sequelize. This module provides a methods to manage notifications with support for real-time updates via WebSockets.

Readme

PSI Notification Server

A custom module for real-time notifications built with Express, Socket.IO, and Sequelize. This module provides a methods to manage notifications with support for real-time updates via WebSockets.

Features

  • Create, update, delete, and fetch notifications.
  • Real-time notifications via WebSockets.
  • Simple integration with an Express app.
  • CORS management for different environments (production, development).
  • Sequelize-based ORM for easy interaction with the database.

Prerequisites

  • Node.js >= 14.x
  • PostgreSQL or any other supported database for Sequelize
  • Express.js
  • Socket.IO

Installation

To integrate this module into your Express app:

  1. Install the module:

    Using npm:

    npm install psi-notification-server

    Or using yarn

    yarn add psi-notification-server
  2. Set up environment variables: Add the following environment variables to your .env file (or in the server environment):

    DB_CONNECTION_STRING=postgres://username:password@localhost:5432/<dbname>
    NODE_ENV=development  # or 'production'

Available Methods:

import { initNotificationModule } from 'psi-notification-server';

const { initializeSocket, addNotification, getNotificationList, updateNotificationStatus, deleteNotification } =
    await initNotificationModule('database-connection-string');

Initialize Socket Connection:

const app = express();
const server = http.createServer(app);
initializeSocket(server);

Notification Props (Interface):

interface NotificationProps {
    receiver_id: number;
    sender_id: number;
    title: string;
    message: string;
    image_url?: string;
    redirect_route?: string;
    type?: string;
    status?: string;
    created_at?: Date;
    updated_at?: Date;
}

Create Notification:

Method: addNotification()

Required Params

notificationData: NotificationProps,
userId?: string

Example

const result = await addNotification(notificationData, userId);

Read Notification:

Method: getNotificationList()

Required Params

receiverId: string,
page: number = 1,
pageSize: number = 10,
status?: string[]       // ['new', 'unread', 'read']

Example

const { data, error } = await getNotificationList('receiverId', 1, 15, ['new', 'unread', 'read']);

Update Notification:

Method: updateNotificationStatus()

Required Params

receiverId: string;
status: string;
notificationIds?: string[]; // Optional

Example

const result = await updateNotificationStatus({
    receiverId,
    'read',
    ['notificationId_1', 'notificationId_2', ...],
});

Delete Notification:

Method: deleteNotification()

Required Params

notificationId: string;

Example

const result = await deleteNotification(notificationId);

Usage

Example: Using the Notification Module in Express

Here’s an example of how to set up and use the notification module in an Express app:

import express, { Request, Response } from 'express';
import http from 'http';
import { initNotificationModule } from 'psi-notification-server';
import cors from 'cors';
import dotenv from 'dotenv';

dotenv.config();

// Setup the database connection string
const connectionString = process.env.DATABASE_URL;

if (!connectionString) {
  throw new Error('DATABASE_URL is not defined in .env');
}

const app = express();
const server = http.createServer(app);

// Middleware and CORS setup
app.use(express.json());
app.use(cors({ origin: '*', methods: ['GET', 'POST', 'PUT'], credentials: true }));

// Initialize Notification Module
async function initializeNotificationModuleAndRoutes() {
  try {
    const { initializeSocket, getNotificationList, updateNotificationStatus, addNotification, deleteNotification } = await initNotificationModule(connectionString);

    // Initialize Socket.IO
    initializeSocket(server);

    // Define the notification routes
    app.get('/notifications/list/:receiverId', async (req: Request, res: Response) => {
      const { receiverId } = req.params;
      const { page = '1', pageSize = '10', status } = req.query;
      const statusArray = status ? String(status).split(',') : ['new'];

      const { data, error } = await getNotificationList(receiverId, Number(page), Number(pageSize), statusArray);
      if (error) return res.status(500).json({ message: error });
      return res.status(200).json({ data });
    });

    // Insert a new notification
    app.post('/notifications/insert', async (req: Request, res: Response) => {
      const { notification, userId } = req.body;
      const requiredFields: (keyof INotification)[] = ['receiver_id', 'sender_id', 'title', 'message', 'status'];
      const missingFields = requiredFields.filter((field) => !notification[field]);

      if (missingFields.length > 0) {
        return res.status(400).json({ error: `Missing required fields: ${missingFields.join(', ')}` });
      }

      const result = await addNotification(notification, userId);  // userId is optional
      return res.json({ data: result.data, error: result.error });
    });

    // Start the server
    server.listen(process.env.PORT, () => {
      console.log('Server is running on port 3001');
    });
  } catch (error) {
    console.error('Error initializing notification module:', error);
  }
}

// Call the initialization function
initializeNotificationModuleAndRoutes();