# promise-ws

> A Promise-Based WebSocket implementation for Node.js

Latest version **1.0.0-1** (published 2018-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-ws
pnpm add promise-ws
yarn add promise-ws
bun add promise-ws
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-1 |
| Published | 2018-08-14 |
| First published | 2017-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 2 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Cap32 |
| Maintainers | cap32 |
| Keywords | websocket, ws, promise, socket |

## Links

- npm: https://www.npmjs.com/package/promise-ws
- Repository: https://github.com/cantonjs/promise-ws
- Homepage: https://github.com/cantonjs/promise-ws#readme
- Issues: https://github.com/cantonjs/promise-ws/issues
- npm.io page: https://npm.io/package/promise-ws

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^6.0.0
- [pify](https://npm.io/package/pify.md) ^3.0.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.0-1 (latest) — 2018-08-14
- 1.0.0-0 — 2018-08-13
- 0.4.1 — 2018-04-23
- 0.4.0 — 2018-04-22
- 0.3.0 — 2018-04-21
- 0.2.2 — 2018-04-10
- 0.2.1 — 2018-03-16
- 0.2.0 — 2018-03-15
- 0.1.0 — 2017-11-27
- 0.0.0 — 2017-11-11
- 0.0.0-1 — 2017-11-03

## README

# promise-ws

[![Build Status](https://travis-ci.org/cantonjs/promise-ws.svg?branch=master)](https://travis-ci.org/cantonjs/promise-ws)
[![CircleCI](https://circleci.com/gh/cantonjs/promise-ws.svg?style=shield)](https://circleci.com/gh/cantonjs/promise-ws)
[![Build status](https://ci.appveyor.com/api/projects/status/q0rmv88vjfk8m2w5/branch/master?svg=true)](https://ci.appveyor.com/project/cantonjs/promise-ws/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/cantonjs/promise-ws/badge.svg?branch=master)](https://coveralls.io/github/cantonjs/promise-ws?branch=master)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
[![License](https://img.shields.io/badge/license-MIT_License-brightgreen.svg?style=flat)](https://github.com/cantonjs/promise-ws/blob/master/LICENSE.md)

A promise based WebSocket implementation for Node.js. Built on top of [ws](https://github.com/websockets/ws)

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Usage examples](#usage-examples)
  - [Simple client](#simple-client)
  - [Simple server](#simple-server)
- [Installation](#installation)
- [API Reference](#api-reference)
- [License](#license)

## Usage examples

### Simple client

```js
import WebSocket from "promise-ws";

(async function() {
  const ws = await WebSocket.create("ws://www.host.com/path");

  ws.on("message", function incoming(data) {
    console.log(data);
  });

  await ws.send("something");
})();
```

### Simple server

```js
import WebSocket from "promise-ws";

(async function() {
  const wss = await WebSocket.Server.create({ port: 8080 });

  wss.on("connection", async function connection(ws) {
    ws.on("message", function incoming(message) {
      console.log("received: %s", message);
    });

    await ws.send("something");
  });
})();
```

## Installation

```bash
$ npm install promise-ws
```

## API Reference

`promise-ws` API is almost the same with [ws](https://github.com/websockets/ws) except that:

- `websocket.ping([data[, mask]])` returns a promise
- `websocket.pong([data[, mask]])` returns a promise
- `websocket.send(data[, options])` returns a promise
- 🆕 `WebSocket.Server.create(options)`, returns a promise of listened `WebSocket.Server` instance
- 🆕 `WebSocket.create(options)`, returns a promise of opened `WebSocket` instance

For more WebSocket API, please checkout the [API doc](https://github.com/websockets/ws/blob/master/doc/ws.md).

## License

MIT

---
_Source: https://npm.io/package/promise-ws · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
