/example-nest-tcp-microservice

An example TCP-based microservice and client built with Typescript and Nestjs.

Primary LanguageTypeScriptGNU Affero General Public License v3.0AGPL-3.0

This project has two binaries actually:

  • a TCP-based microservice using Nestjs; and
  • a corresponding TCP client which invokes a remote procedure and prints the output.

tl;dr

$ npm install

# start the server on 0.0.0.0:1888
$ npm run start:dev

# in another shell, run the client
$ npx ts-node src/client

The client will send both request-response and event-based messages:

  • a request CmdHello which expects an Observable<string> in return; and
  • an event EvtAhoy which is broadcast to the server in its own namespace.
$ npx ts-node src/client
[Nest] 812632   - 04/26/2021, 8:53:45 AM   [NestFactory] Starting Nest application...
[Nest] 812632   - 04/26/2021, 8:53:45 AM   [InstanceLoader] ClientsModule dependencies initialized +23ms
[Nest] 812632   - 04/26/2021, 8:53:45 AM   [InstanceLoader] ClientModule dependencies initialized +0ms
sending request for hello
emitting event: ahoy
got value: Hello from the server!
Shutting down ...

Meanwhile, the server should look something like:

$ npm run start:dev
[Nest] 812606   - 04/26/2021, 8:53:41 AM   [NestFactory] Starting Nest application...
[Nest] 812606   - 04/26/2021, 8:53:41 AM   [InstanceLoader] ServerModule dependencies initialized +25ms
[Nest] 812606   - 04/26/2021, 8:53:41 AM   [NestMicroservice] Nest microservice successfully started +3ms
Microservice is listening
data: 
"ahoy" broadcast from the client

The rest of this document is the auto-generated Nestjs documentation!


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 Support us

Description

Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.