Socket
Book a DemoInstallSign in
Socket

lup-express-ws

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lup-express-ws

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

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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.

Keywords

node

FAQs

Package last updated on 28 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts