# grpc-node-server-interceptors

> This package provides an interface for gRPC Servers from `@grpc/grpc-js` to be created with interceptors. Allows for intercepting incoming requests from gRPC clients as well as intercepting outgoing responses from the server.

Latest version **1.0.1** (published 2021-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install grpc-node-server-interceptors
pnpm add grpc-node-server-interceptors
yarn add grpc-node-server-interceptors
bun add grpc-node-server-interceptors
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-02-23 |
| First published | 2021-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Javier Velazquez |
| Maintainers | papajuanito |

## Links

- npm: https://www.npmjs.com/package/grpc-node-server-interceptors
- Repository: https://github.com/papajuanito/grpc-node-server-interceptors
- npm.io page: https://npm.io/package/grpc-node-server-interceptors

## Dependencies (1)

- [@grpc/grpc-js](https://npm.io/package/@grpc/grpc-js.md) ^1.2.8

## Recent versions

- 1.0.1 (latest) — 2021-02-23
- 1.0.0 — 2021-02-21

## README

# gRPC NodeJS Server Interceptors

This package provides an interface for gRPC Servers from `@grpc/grpc-js` to be created with interceptors. Allows for intercepting incoming requests from gRPC clients as well as intercepting outgoing responses from the server.

## Installation

### npm:

```bash
npm install grpc-node-server-interceptors
```

### yarn:

```bash
yarn add grpc-node-server-interceptors
```

## Examples

This example shows how to intercept incoming gRPC client requests on your gRPC server:

```ts
import { status as GrpcStatus } from '@grpc/grpc-js`;
import GrpcServerWithInterceptors, { ServerInterceptor, ServerInterceptingCall } from 'grpc-node-server-interceptors';

const interceptors: ServerInterceptor<RequestType, RequestResponse>[] = [
  (call, nextCall) => {
    return new ServerInterceptingCall(nextCall(call), {
      // This is called on every incoming client request before sent to the original handler
      onReceiveMessage: (message, next) => {
        // Continue unto the next interceptor
        next(message);
      },
      // This is called on every outgoing server response before it is sent to the client
      onSendMessage: (response, next) => {
        if (response.status !== GrpcStatus.OK) {
          log.error(response.status);
        }
        next(response);
      },
    });
  }
]

const server = new GrpcServerWithInterceptors({
  ...channelOptions,
  // List of global interceptors. These will be applied to all services added to the server through `addService`.
  interceptors,
});

// Consume the new server the same way you would with `grpc.Server`
server.addService(serviceDefinition, handlers);

server.bindAsync(...);

```

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