[Solved] Can grpc and express server run by same nodejs server, or grpc has to be different server
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.
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");
});
Read more here: Source link