Notary Public Mystifier

    lup-express-ws
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    GitHub package.json version npm bundle size GitHub Workflow Status NPM

    lup-express-ws

    Node module that provides WebSocket server functionality for express while being compatible with other websocket servers like webpack-hot-client or next.js

    How to use

    JavaScript

    const express = require('express');
    const wss = require('lup-express-ws')(express());
    const app = wss.app;
    
    app.ws("/", function(ws, req){
        ws.on('message', function(event){
            ws.send("Hello World");
        });
    });
    
    
    // or with routers
    const router = express.Router();
    router.ws("/", function(ws, req){
        ws.on('message', function(event){
            ws.send("Hello World");
        });
    });
    
    app.use(router);

    TypeScript

    You additionally need to install npm install --save-dev @types/ws

    import express from 'express';
    import expressWs from 'lup-express-ws';
    import { WebSocket } from 'ws';
    
    const wss = expressWs(express());
    const app = wss.app;
    
    app.ws("/", function(ws: WebSocket, req: express.Request){
        ws.on('message', function(event: any){
            ws.send("Hello World");
        });
    });
    
    
    // or with routers
    const router = express.Router() as expressWs.Router;
    router.ws("/", function(ws: Websocket, req: express.Request){
        ws.on('message', function(event: any){
            ws.send("Hello World");
        });
    });

    Credits

    This module is inspired by the express-ws module! However since the express-ws isn't compatible with other websocket server modules, this one got created.

    Install

    npm i lup-express-ws

    DownloadsWeekly Downloads

    32

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    10 kB

    Total Files

    5

    Last publish

    Collaborators

    • luca-vogels