Microservice with Golang, NodeJS and gRPC (Part 2)

Tram Ho

Continuing part 1 , this part I will create a node server to connect to the core server and also just to display hello world

Node Server

  • Similar to the previous part, this part I will create a proto folder, but inside it is a little more complicated because we have to compile proto to js.
  • Create a package.json file on the same level as helloworld.proto

package.json

To make it easier to generate complie file, I have written the script and you just need to run npm run proto-gen (after npm install) is ok, and the directory structure will look like this.

After completing proto, I will create app.js file to make connecting to core server and still create package.json look like this.

and the app.js file

Reading the code is also very easy to understand, isn’t it =))

(The result line above is test with go-server )

And here is the output after running the command node app.js

And here is my entire directory structure

If you develop microservice, then in my opinion you should create each server as a separate development github (at least by module) to try not to affect as much as possible on what was done, and a single line github dedicated to proto development.

End

  • So I have completed the use of microservice with golang-golang , golang-nodejs (communication between servers).
  • And here is the source code of the two parts I wrote
Share the news now

Source : Viblo