# @exotjs/express

> An Express middleware for Exot Inspector.

Latest version **0.1.0** (published 2024-02-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @exotjs/express
pnpm add @exotjs/express
yarn add @exotjs/express
bun add @exotjs/express
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2024-02-16 |
| First published | 2024-02-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Daniel Regeci |
| Maintainers | ovx |
| Keywords | exot, inspector, express, middleware |

## Links

- npm: https://www.npmjs.com/package/@exotjs/express
- npm.io page: https://npm.io/package/@exotjs/express

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2024-02-16

## README

# Express Middleware for Exot Inspector

This package includes an Express middleware for automatic request tracing, an error handler for tracking Express errors, and a WebSocket server for communication between the server and the app.

## Features

- Automatic request tracing (use `middleware` to enable)
- Error tracking (use `errorHandler` to enable)
- Built-in WebSocket server for server-app communication channel

## Usage

```ts
import { createServer } from 'node:http';
import { errorHandler, middleware, websocketServer } from '@exotjs/express';
import { Inspector } from '@exotjs/express/inspector';
import { MemoryStore } from '@exotjs/express/store';
import express from 'express';

const app = express();

// 1. Instantiate the inspector
const inspector = new Inspector({
  store: new MemoryStore(),
});

const server = createServer(app);

// 2. Mount the middleware
app.use(middleware({
  inspector,
}));

app.get('/', (req, res) => {
  res.send('Hello');
});

// 3. Mount the error handler
app.use(errorHandler({
  inspector,
}));

server.listen(3002);

// 4. Start the websocket server
websocketServer({
  authorize: async (req) => {
    // check request somehow, throw an error if not authorized
  },
  inspector,
  path: '/_inspector',
  server,
  ws: {
    noServer: true,
  },
});

```

## Tracing

Use the [trace](https://github.com/exotjs/trace) package for easy application tracing. It works automatically even for nested traces, without passing around any context.

```ts
import { Tracer } from '@exotjs/trace';

const tracer = new Tracer();
const { trace } = tracer;

// Now simply use `trace()` anywhere in your code
trace('mytrace', () => {
  // some work...
})
```

Alternatively, use the `inspect.instruments.traces.trace()` function.

## Contributing

See [Contributing Guide](https://github.com/exotjs/express/blob/main/CONTRIBUTING.md) and please follow our [Code of Conduct](https://github.com/exotjs/express/blob/main/CODE_OF_CONDUCT.md).

## License

MIT

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