1.0.2 • Published 2 years ago

lup-express-ws v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 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

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.20

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.17

2 years ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago