Registry / devops / grpc-web-middleware

grpc-web-middleware

JSON →
library0.2.3jsnpmunverified

grpc-web-middleware v0.2.3 is a lightweight Node.js middleware that acts as a gRPC-Web gateway, enabling gRPC-Web clients to communicate with gRPC servers via HTTP/1.1. It is designed for simplicity and minimal configuration, integrating easily with Express and Koa. The package has not been updated since 2019 and lacks TypeScript definitions, but remains functional for basic gRPC-Web proxying. It differs from alternatives like grpc-web by focusing on server-side middleware rather than client-side libraries.

npm install grpc-web-middleware
INSTALL
IMPORT
SIG · GRPC-WEB-MIDDLEWAR
G
grpc-web-middleware
devopsjavascriptv0.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const grpcWebMiddleware = require('grpc-web-middleware')
import grpcWebMiddleware from 'grpc-web-middleware'
Package uses CommonJS only; ESM import may fail without default interop.
default
import grpcWebMiddleware from 'grpc-web-middleware'
Only if using ESM with module bundler that supports CJS interop; Node.js native ESM may require createRequire.
default
const { grpcWebMiddleware } = require('grpc-web-middleware')
const grpcWebMiddleware = require('grpc-web-middleware').default
Package does not export named exports; avoid destructuring or accessing .default.

Create an Express server with CORS that proxies gRPC-Web requests to a gRPC server at localhost:6565.

const express = require('express'); const cors = require('cors'); const grpcWebMiddleware = require('grpc-web-middleware'); const app = express(); app.use(cors()); app.use(grpcWebMiddleware('http://localhost:6565')); app.listen(8080, () => { console.log('gRPC-Web proxy running on port 8080'); });
Debug
Known issues
gotchaMiddleware does not handle CORS automatically; you must add your own CORS middleware.
fix
Add cors() or @koa/cors before the gRPC middleware.
affects: >=0.0.0
gotchaThe middleware expects req and res objects similar to Node's http.ServerResponse; in Koa, you must pass ctx.req and ctx.res explicitly.
fix
Use async (ctx, next) => grpcWebMiddleware(url)(ctx.req, ctx.res, next).
affects: >=0.0.0
gotchaIf using a prefix, ensure it starts with '/' and does not end with '/', otherwise routing may fail.
fix
Use prefix like '/api' (not '/api/' or 'api').
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'grpc-web-middleware'
Package not installed or npm install failed.
fix
Run 'npm install grpc-web-middleware' in your project.
TypeError: grpcWebMiddleware is not a function
Incorrect import style (e.g., destructuring or trying to import default as named).
fix
Use 'const grpcWebMiddleware = require('grpc-web-middleware')' (no destructuring).
ERR_REQUIRE_ESM: require() of ES Module not supported
Package is CJS but you are trying to require it from an ESM context without proper interop.
fix
Use dynamic import or createRequire from 'module'.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
grpc-web-middleware — npm install grpc-web-middleware · libregistry