This is a demo project to showcase a gRPC server and client for Node.js with TypeScript.
- TypeScript for client and server:
nice-grpc
(npm) for the main gRPC client and server
- Schema-first protobuf definitions with code generation
- Schema linting for best practices
@bufbuild/buf
(npm) for CLI linting and lint rules definition
- Server reflection for introspection from client
- Code generation for client with reflection
- Server health check procedures
nice-grpc-server-health
(npm) for implementation of gRPC health v1 standard
- Server middlewares
nice-grpc-server-terminator
(npm) to facilitate server graceful shutdown
- Client middlewares
- OpenTelemetry tracing
nice-grpc-opentelemetry
(npm) for server tracing with OpenTelemetry instrumentation
- Node.js 20.x (if not using
direnv
withnix-shell
) - Docker for usage of grpcurl to run client introspection of server reflection
- (Optional) If using
direnv
withnix-shell
, rundirenv allow
- Run
npm install
to install dependencies - For
./server
and./client
, runcp .env.sample .env
to create environment files - In both
.env
files, replace<server-token-here>
with the same string to use as auth token
npm run dev
: to start the server for development in watch modenpm run serve
: to build and start the server in production modenpm run build
: to codegen the Protobuf schema and build the sourcenpm run proto:build
: to only codegen the Protobuf schemanpm run server:build
: to only build the server sourcenpm start
: to start the server in production mode (manualbuild
is needed before)
To run the client, the server must be running in the address specified in
the .env
file (localhost:50051
by default).
npm run dev
: to start the client in development in watch modenpm run serve
: to build and start the client in production modenpm run proto
: to run the client codegen from server reflection (requires Docker)npm run build
: to build the client sourcenpm start
: to start the client in production mode (manualbuild
is needed before)