# setup-socket.io

> ### Functions:

Latest version **1.1.1** (published 2021-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install setup-socket.io
pnpm add setup-socket.io
yarn add setup-socket.io
bun add setup-socket.io
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-06-14 |
| First published | 2021-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | nghia |
| Maintainers | nqnghia285 |
| Keywords | setup-socket.io, initIO, createNamespace |

## Links

- npm: https://www.npmjs.com/package/setup-socket.io
- Repository: https://github.com/nqnghia285/setup-socket.io
- Homepage: https://github.com/nqnghia285/setup-socket.io.git#readme
- npm.io page: https://npm.io/package/setup-socket.io

## Dependencies (3)

- [http](https://npm.io/package/http.md) ^0.0.1-security
- [socket.io](https://npm.io/package/socket.io.md) ^4.0.1
- [socket.io-cookies-parser](https://npm.io/package/socket.io-cookies-parser.md) ^1.1.1

## 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.1.1 (latest) — 2021-06-14
- 1.1.0 — 2021-06-11
- 1.0.9 — 2021-05-12
- 1.0.8 — 2021-04-13
- 1.0.7 — 2021-04-12
- 1.0.6 — 2021-04-12
- 1.0.5 — 2021-04-12
- 1.0.4 — 2021-04-12
- 1.0.3 — 2021-04-12
- 1.0.2 — 2021-04-12
- 1.0.1 — 2021-04-11
- 1.0.0 — 2021-04-11

## README

# `Setup Socket.IO` [![Build Status](https://github.com/Links2004/arduinoWebSockets/workflows/CI/badge.svg?branch=master)](https://github.com/nqnghia285/setup-socket.io.git)

### Functions:

```typescript
/**
 * @method initIO Initiate io instance
 * @param server Server
 * @param origin string
 * @returns socketio.Server
 */
function initIO(server: Server, origin: string): socketio.Server;
```

```typescript
/**
 * @method createNamespace Create namespace of io
 * @param nsp string
 * @returns Namespace
 */
function createNamespace(nsp: string): Namespace;
```

### Example:

```typescript
// ES6
import dotenv from "dotenv";
import { createServer } from "http";
import express from "express";
import { Socket } from "socket.io";
import io, { createNamespace, initIO } from "setup-socket.io";

dotenv.config();

const ORIGIN = process.env.ORIGIN || "*";

const app = express();
const server = createServer(app);

// Init io
initIO(server, ORIGIN);

// Create client namespace
const client = createNamespace("/client");

io.on("connection", (socket: Socket) => {
    socket.on("your-event", (message) => {
        console.log(message);
        console.log("Cookies:", socket.request.cookies);
    });
});

client.on("connection", (socket: Socket) => {
    socket.on("your-event", (message) => {
        console.log(message);
        console.log("Cookies:", socket.request.cookies);
    });
});
```

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