# express.io-middleware

> This Express.io extension adds middleware and multiroute functionality to app.io

Latest version **0.9.4** (published 2014-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install express.io-middleware
pnpm add express.io-middleware
yarn add express.io-middleware
bun add express.io-middleware
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.4 |
| Published | 2014-07-30 |
| First published | 2013-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Yurij Mikhalevich |
| Maintainers | 39dotyt |
| Keywords | express.io, middleware, socket.io, express, event name |

## Links

- npm: https://www.npmjs.com/package/express.io-middleware
- Repository: https://github.com/39dotyt/express.io-middleware
- Issues: https://github.com/39dotyt/express.io-middleware/issues
- npm.io page: https://npm.io/package/express.io-middleware

## Dependencies (1)

- [underscore](https://npm.io/package/underscore.md) ~1.5.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

- 0.9.4 (latest) — 2014-07-30
- 0.9.3 — 2014-07-19
- 0.9.2 — 2014-07-19
- 0.9.1 — 2013-08-22
- 0.9.0 — 2013-08-22

## README

# express.io-middleware

This Express.io extension adds middleware and multiroute functionality to app.io. It also adds app.io.event
and app.io.namespace properties, which contains signal name and namespace (before ':' part) respectively.

Tested with express.io 1.1.x.

Installation:

```bash
$ npm install express.io-middleware
```

Example:

```javascript
// ...
app.http().io();

require('express.io-middleware')(app); // first of all, you should patch express.io app after calling app.io();

/**
* @param {Object} req Is express.io request object
* @param {Function} next Is a pointer to the next handler in chain.
*/
app.io.use(function (req, next) {
  console.log(req.data);
  if (!req.data) {
    req.respond(':-(');
  } else {
    next();
  }
});

/**
* You may use regular expressions to bind middleware execution only for specified signals.
*/
app.io.use(/.+:save/, function (req, next) {
  if (typeof req.data != 'object') {
    req.io.emit('invalid data received');
  } else {
    next();
  }
});

app.io.route('entity', {
  save: function (req, next) {}
});

/**
* Also, you may build chain of signals handlers.
*/
app.io.route('entity:save', endpoint);
```

Note that all middlewares should be declared strongly before declaration of routes, for which it should be applied.

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