This project demonstrates a simple microservices architecture using gRPC and Node.js. It consists of three services:
- main: REST API gateway and gRPC client
- degree: Degree selector microservice (gRPC server)
- process: Onboarding processing microservice (gRPC server with streaming)
grpc-js/
├── main/
│ └── main.js # Main microservice (REST + gRPC client)
├── degree/
│ └── main.js # Degree microservice (gRPC server)
├── process/
│ └── main.js # Processing microservice (gRPC server, streaming)
├── protos/
│ ├── degree.proto # Protobuf for degree service
│ └── processing.proto# Protobuf for processing service
├── package.json
├── .gitignore
└── README.md
- Node.js
- Express
- @grpc/grpc-js
- @grpc/proto-loader
- concurrently
- Protocol Buffers (Protobuf)
-
Clone the repository
git clone https://github.com/sdshah09/gRPC-JS.git cd grpc-js -
Install dependencies
npm install
-
Project structure
main/- REST API and gRPC clientdegree/- Degree gRPC serverprocess/- Processing gRPC server (with streaming)protos/- Protobuf definitions
-
Run all services concurrently Add this to your
package.jsonscripts section:"scripts": { "start": "concurrently \"node degree/main.js\" \"node process/main.js\" \"node main/main.js\"" }
Then run:
npm start
- Runs on port 3000
- Endpoints:
GET /degree/:id- Get degree information by IDPOST /process- Start onboarding process (body:{ "degreeId": <number>, "orderId": <number> })
- Runs on port 50051
- Implements the
FindRPC to return degree info by ID
- Runs on port 50052
- Implements the
ProcessRPC to stream onboarding status updates
See protos/degree.proto and protos/processing.proto for service and message definitions.
- Modify or add services in their respective folders
- Update protobufs in
protos/and reload in your services as needed - Use
npm startto run all services together
MIT