Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

ws 8.15.1

Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js
Package summary
Share
0
issues
0
licenses
Package created
4 Dec 2011
Version published
12 Dec 2023
Maintainers
4
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does ws do?

The "ws" is a simple-to-use, supremely fast, and robustly tested WebSocket client and server implementation for Node.js. With "ws", you can effortlessly establish real-time, two-way channels of communication between the server and the client thereby making it a top choice for building real-time applications.

How do you use ws?

To start using the "ws" library, first install it using npm:

npm install ws

Then instantiate either the WebSocket client or the WebSocket server:

  • Client Example:
import WebSocket from 'ws';

const ws = new WebSocket('ws://www.host.com/path');

ws.on('open', function open() {
  ws.send('something'); // send a message
});

ws.on('message', function message(data) {
  console.log('received: %s', data); // print all received messages
});
  • Server Example:
import { WebSocketServer } from 'ws';

const wss = new WebSocketServer({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function message(data) {
    console.log('received: %s', data); // print all received messages
  });

  ws.send('something'); // send a message
});

Please note, 'ws' does not work in a browser environment. To make the same code work seamlessly between Node.js and the browser, consider using a wrapper like isomorphic-ws.

Where are the ws docs?

The extensive documentation for the "ws" library can be found in the ws.md file in the docs folder of the project repository. The API Docs section provides a detailed explanation of all classes and utility functions provided by the "ws" library. The documentation is designed on the lines of Node.js documentation to make it easily comprehensible for developers familiar with Node.js.