Project Q-Microservices

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Donate Support us Follow us on Twitter

Description

Nest framework TypeScript starter repository.

Project setup

pnpm install

Compile and run the project

# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod

Run tests

# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov

Resources

Check out a few resources that may come in handy when working with NestJS:

  • Visit the NestJS Documentation to learn more about the framework.
  • For questions and support, please visit our Discord channel.
  • To dive deeper and get more hands-on experience, check out our official video courses.
  • Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
  • Need help with your project (part-time to full-time)? Check out our official enterprise support.
  • To stay in the loop and get updates, follow us on X and LinkedIn.
  • Looking for a job, or have a job to offer? Check out our official Jobs board.

License

Nest is MIT licensed.

Mar Documentation

Note: Tutorial Link to follow

Steps

  1. Install the required packages by running the following command:

    # to get the latest nestjs version on your projects (globally)
    $ npm install -g @nestjs/cli@latest
    
    # to start this project
    $ nest new q-micro-services

    Installation process

    Note: I use pnpm as the package manager.

  2. Test:

    Package installation

  3. Create our microservice to Manage Courses, but first we need to convert this project to mono-repo:

    # generate microservice for courses
    # microservice would be the folder, and course will be a sub directory that will handle the things for the microservices
    $  nest generate microservice course
    
    # but for convention I used app/course
    $  nest generate app course

    file-structure:

    alt text

    nest-cli.json:

    alt text

  4. Renaming for uniform code: From Q-Micro-Service -> api-gateway

    For a proper API naming of the api-gateway that will recieve all the traffice of all the http request in the app by proxing those calls to the microservices using gRPC.

    alt text

    Note: I still save some of the app name, so you still can search q-microservices

  5. Test the courses

    # you can test to its specific gateway
    $ pnpm run start:dev course

    This will cause an error because of the image below and still listening to both port 3000. We can solve it using gRPC.

    alt text

    So we will install grpc and grpc-tools to generate the proto file and the client for the microservices.

    # you can test to its specific gateway
    $ pnpm i --save @nestjs/microservices @grpc/grpc-js @grpc/proto-loader ts-proto

    Remove files apps ---- api-gate-way ---- course ---------src ------------ course.controller (remove) ------------ course.service (remove)

    And remove all its import in the course module, then we will use commandline to generate its resouces to perform CRUD.

    # you can test to its specific gateway
    $ nest g resource course
    # then choose course (microservice and y), this will generate files from course folder 
  6. Current

    protoc --plugin=./node_modules/. bin/protoc-gen-ts_proto --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/course.proto It seems that protoc, the Protocol Buffers compiler, is not installed on your system. You will need to install it to be able to compile .proto files. Here’s how you can install and set it up:

Step 1: Install protoc

To install protoc, follow the appropriate steps based on your operating system:

For Windows (using Chocolatey)

  1. Open PowerShell as Administrator.

  2. Run the following command:

    choco install protoc
  3. Verify the installation by checking the version:

    protoc --version

Step 2: Install ts-proto and other dependencies

Ensure you have ts-proto installed in your project:

npm install ts-proto

Step 3: Generate TypeScript Protobuf Files

Once protoc is installed, you should be able to run the command to generate the TypeScript code with nestJs options:

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/course.proto

Step 4: Verify the Setup

If everything is installed correctly, running protoc --version should display the version number, and the generation of TypeScript files should work as expected.

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/course.proto protoc --plugin=protoc-gen-ts_proto=C:/Users/joema/AppData/Roaming/npm/protoc-gen-ts_proto.cmd --ts_proto_out=./src --ts_proto_opt=nestJs=true ./proto/course.proto