I am trying to create a REST server which will be based on Node/Express. How to add a GRPC server in the same REST server, or it has to be completely different NodeJS server which will host only the GRPC server.
Asked
Active
Viewed 2,760 times
2 Answers
4
You cannot add a gRPC server to an Express server. You can run a gRPC server in the same process as an Express server, but they will serve on separate ports and run independently.

murgatroid99
- 19,007
- 10
- 60
- 95
-
-
@Asutosh would you mind adding your own answer or expand this one to show how you actually did it? Thanks. – Archimedes Trajano Nov 10 '20 at 19:38
0
This is what I did which is basically triggering the GRPC server start on the listen
callback of express
import express from "express";
import { Server, ServerCredentials } from "grpc";
const server = new Server();
server.bind('0.0.0.0:50051', ServerCredentials.createInsecure());
const router = express.Router();
express()
.use("/", router)
.listen(3000, () => {
server.start();
console.log("listening");
});

Archimedes Trajano
- 35,625
- 19
- 175
- 265