1.0.2 • Published 3 years ago

lup-express-ws v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago